Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Version 2
- library(devtools)
- #install_github("jcheng5/bubbles",force = TRUE)
- library(bubbles)
- library(lubridate)
- library(tidyverse)
- library(fasttime)
- library(shiny)
- library(shinydashboard)
- library(RPostgres)
- library(DBI)
- library(scales)
- library(dygraphs)
- library(xts)
- guaranteesquery <- "select vehicles.id, vehicles.licence_plate, vehicles.guarantee_start_date, vehicles.guarantee_end_date,vehicles.guarantee_amount from vehicles where vehicles.state = 'enabled'"
- bookingsquery <- "select bookings.id as booking_id,bookings.driver_id, driver_plans.start_time, case when driver_plans.end_time = 'infinity' then NULL else driver_plans.end_time end, driver_plans.created_at, driver_plans.booking_amount_before_discount_pence as b, driver_plans.insurance_pence as i, driver_plans.vehicle_discount_percent as d, driver_plans.owner_price_before_discount_pence as o from driver_plans left join bookings on driver_plans.booking_id = bookings.id where driver_plans.state = 'booked' and bookings.fleet_organisation_id is null"
- con <- dbConnect(RPostgres::Postgres(),dbname = 'd6fpj3q9fd7ir0', host = 'ec2-34-201-185-191.compute-1.amazonaws.com', port = 5432, user = 'uas5mog87kfvp1', password = 'phajrgnbciabq1l0kqv45kohq')
- bookings <- dbGetQuery(con, bookingsquery) %>% as.tibble()
- bookings$b <- bookings$b/100
- bookings$i <- bookings$i/100
- bookings$o <- bookings$o/100
- bookings$d <- (100-bookings$d)/100
- vehicles_on_hire <- dbGetQuery(con,
- "select vehicles.id as vehicle_id, vehicle_make, year, sub_type, driver_plans.booking_amount_before_discount_pence/100 as list_price,
- case when companies.name is null then concat(partners.first_name,' ',partners.last_name,'*') else companies.name end as Supplier,
- bookings.owner_id,bookings.id as booking_id, bookings.start_time, bookings.end_time
- from vehicles
- left join bookings on bookings.vehicle_id = vehicles.id
- left join driver_plans on driver_plans.booking_id = bookings.id
- left join companies on companies.partner_id = vehicles.owner_id
- left join partners on bookings.owner_id = partners.id
- where vehicles.state = 'enabled' and
- (driver_plans.end_time>=now() or driver_plans.end_time = 'infinity') and bookings.state = 'booked'
- and bookings.fleet_organisation_id is null") %>% as.tibble()
- vehicles_available <- dbGetQuery(con,
- "select vehicles.owner_id,
- case when companies.name is null then concat(partners.first_name,' ',partners.last_name,'*') else companies.name end as Supplier,
- vehicles.id as vehicle_id,
- vehicles.vehicle_make, vehicles.vehicle_model, vehicles.year, vehicles.licence_plate from vehicles
- left join companies on companies.partner_id = vehicles.owner_id
- left join partners on partners.id = vehicles.owner_id where vehicles.state = 'enabled'") %>% as.tibble()
- vehicles_enabled <- full_join(vehicles_available,vehicles_on_hire,by = c("vehicle_id","supplier","year","vehicle_make"))
- cohorts <- bookings %>% group_by(driver_id) %>% summarise(time_of_conception = min(created_at),cohort = min(start_time) %>% format("%Y %m"), cohort_year = min(start_time) %>% format("%Y"), cohort_start = min(start_time) %>% format("%Y-%m-01") %>% as.Date("%Y-%m-%d"))
- chris <- function(date1,date2) {
- #date1 <- Sys.Date()+1
- #date2 <- Sys.Date() %>% format("%Y-%m-01") %>% as.Date()
- bookings$start_time <- as.Date(bookings$start_time)
- bookings$end_time <- as.Date(bookings$end_time)
- bookings$d <- (100-bookings$d)/100
- bookings <- bookings %>% mutate(GMV = ((b-i)*d+i),
- GMV_pre_insurance = (b-i)*d,
- Commission = (b-i-o)*d,
- Payout = o*d, Insurance = i)
- bookings <- bookings %>% filter((start_time<date2 & end_time>=date1) | (start_time>=date2 & end_time<date1) | (start_time<date2 & end_time<date1 & end_time>=date2) | (start_time>=date2 & start_time<date1 & end_time>=date1) |(is.na(end_time) & start_time<date1) ) %>%
- mutate(duration_in_given_interval = ifelse(!is.na(end_time),
- ifelse(start_time<date2 & end_time>=date1,(date1-date2) %>% as.numeric(),
- ifelse(start_time<date1 & start_time>=date2 & end_time>=date2 & end_time<date1,end_time-start_time,
- ifelse(end_time>=date1,date1-start_time-1,end_time-date2+1))),
- ifelse(start_time<date2,date1-date2,date1-start_time-1)),
- dp_gmv = duration_in_given_interval*GMV/7, dp_gmv_pre_insurance = duration_in_given_interval*GMV_pre_insurance/7, dp_booking_commission = duration_in_given_interval*Commission/7,dp_insurance = duration_in_given_interval*Insurance/7,dp_payout = duration_in_given_interval*Payout/7)
- KPIS <- bookings %>% summarise(Commission = sum(dp_booking_commission),Insurance = sum(dp_insurance),Payout = sum(dp_payout),GMV = sum(dp_gmv),date = date2 %>% format("%b %y"), date2 = date2 %>% as.Date())
- print(KPIS)}
- x1 <- seq(as.Date("2016-05-01"), as.Date("2017-11-01"), "months")
- x2 <- seq(as.Date("2016-06-01"), as.Date("2017-12-01"), "months")
- x <- map2(x2,x1,chris) %>% bind_rows %>% select(GMV,Commission,Payout,date,date2) %>% gather(key = "Metric",Amount,-c(date,date2))
- ts1 <- map2(x2,x1,chris) %>% bind_rows %>% select(GMV,Commission,Payout,date,date2) %>% gather(key = "Metric",Amount,-c(date,date2))
- current_bookings <- bookings %>% filter(start_time<=Sys.time(),is.na(end_time) | end_time>=Sys.time()) %>% mutate(duration_to_date = ifelse(is.na(end_time),difftime(Sys.Date(),start_time,units = "days"),difftime(end_time,start_time,units = "days")), type = ifelse(is.na(end_time),"Rolling","Fixed")) %>%
- group_by(type) %>% summarise(count = n(), avg_duration = mean(duration_to_date), posy = cumsum(count)-(count/2)) %>% mutate(posx = ifelse(type=="Rolling",0.75,0.25))
- #Monthly KPIS per second
- insert_date_monthly2 <- Sys.Date()+1
- prev_date_monthly2 <- Sys.Date() %>% format("%Y-%m-01") %>% as.Date()
- bookings_monthly2 <- bookings
- bookings_monthly2$d <- (100-bookings_monthly2$d)/100
- bookings_monthly2 <- bookings_monthly2 %>% mutate(GMV = ((b-i)*d+i),
- GMV_pre_insurance = (b-i)*d,
- Commission = (b-i-o)*d,
- Payout = o*d, Insurance = i, start_time2 = start_time)
- bookings_monthly2$start_time <- fastPOSIXct(bookings_monthly2$start_time) %>% format("%Y-%m-%d") %>% as.Date()
- bookings_monthly2$end_time <- fastPOSIXct(bookings_monthly2$end_time) %>% format("%Y-%m-%d") %>% as.Date()
- #driver_cohorts <- bookings_monthly2 %>% group_by(driver_id) %>% summarise(cohort = min(start_time) %>% format("%Y %m"), cohort_year = min(start_time) %>% format("%Y"), cohort_start = min(start_time) %>% format("%Y-%m-01") %>% as.Date("%Y-%m-%d"))
- bookings_monthly2 <- bookings_monthly2 %>% filter((start_time<prev_date_monthly2 & end_time>=insert_date_monthly2) | (start_time>=prev_date_monthly2 & end_time<insert_date_monthly2) | (start_time<prev_date_monthly2 & end_time<insert_date_monthly2 & end_time>=prev_date_monthly2) | (start_time>=prev_date_monthly2 & start_time<insert_date_monthly2 & end_time>=insert_date_monthly2) |(is.na(end_time) & start_time<insert_date_monthly2) ) %>%
- mutate(duration_in_given_month = ifelse(!is.na(end_time),
- ifelse(start_time<prev_date_monthly2 & end_time>=insert_date_monthly2,(insert_date_monthly2-prev_date_monthly2) %>% as.numeric(), ifelse(start_time<insert_date_monthly2 & start_time>=prev_date_monthly2 & end_time>=prev_date_monthly2 & end_time<insert_date_monthly2,end_time-start_time,ifelse(end_time>=insert_date_monthly2,insert_date_monthly2-start_time-1,end_time-prev_date_monthly2+1))), ifelse(start_time<prev_date_monthly2,insert_date_monthly2-prev_date_monthly2,insert_date_monthly2-start_time-1)),
- dp_gmv = duration_in_given_month*GMV/7, dp_gmv_pre_insurance = duration_in_given_month*GMV_pre_insurance/7, dp_booking_commission = duration_in_given_month*Commission/7,dp_insurance = duration_in_given_month*Insurance/7,dp_payout = duration_in_given_month*Payout/7)
- x <- bookings_monthly2 %>% select(start_time2,end_time,GMV,GMV_pre_insurance,Commission,Payout,Insurance,duration_in_given_month)
- #Monthly KPIS
- {insert_date_monthly <- Sys.Date()+1
- prev_date_monthly <- Sys.Date() %>% format("%Y-%m-01") %>% as.Date()
- bookings_monthly <- bookings
- bookings_monthly$d <- (100-bookings_monthly$d)/100
- bookings_monthly <- bookings_monthly %>% mutate(GMV = ((b-i)*d+i),
- GMV_pre_insurance = (b-i)*d,
- Commission = (b-i-o)*d,
- Payout = o*d, Insurance = i)
- bookings_monthly$start_time <- fastPOSIXct(bookings_monthly$start_time) %>% format("%Y-%m-%d") %>% as.Date()
- bookings_monthly$end_time <- fastPOSIXct(bookings_monthly$end_time) %>% format("%Y-%m-%d") %>% as.Date()
- driver_cohorts <- bookings_monthly %>% group_by(driver_id) %>% summarise(cohort = min(start_time) %>% format("%Y %m"), cohort_year = min(start_time) %>% format("%Y"), cohort_start = min(start_time) %>% format("%Y-%m-01") %>% as.Date("%Y-%m-%d"))
- bookings_monthly <- bookings_monthly %>% filter((start_time<prev_date_monthly & end_time>=insert_date_monthly) | (start_time>=prev_date_monthly & end_time<insert_date_monthly) | (start_time<prev_date_monthly & end_time<insert_date_monthly & end_time>=prev_date_monthly) | (start_time>=prev_date_monthly & start_time<insert_date_monthly & end_time>=insert_date_monthly) |(is.na(end_time) & start_time<insert_date_monthly) ) %>%
- mutate(duration_of_driver_plan = ifelse(!is.na(end_time),(end_time-start_time),(insert_date_monthly-start_time)),
- duration_to_date = ifelse((start_time>insert_date_monthly) | is.na(end_time), insert_date_monthly-start_time, end_time-start_time),
- duration_in_given_month = ifelse(!is.na(end_time),
- ifelse(start_time<prev_date_monthly & end_time>=insert_date_monthly,(insert_date_monthly-prev_date_monthly) %>% as.numeric(), ifelse(start_time<insert_date_monthly & start_time>=prev_date_monthly & end_time>=prev_date_monthly & end_time<insert_date_monthly,end_time-start_time,ifelse(end_time>=insert_date_monthly,insert_date_monthly-start_time-1,end_time-prev_date_monthly+1))), ifelse(start_time<prev_date_monthly,insert_date_monthly-prev_date_monthly,insert_date_monthly-start_time-1)),
- duration_projection = ifelse(!is.na(end_time),duration_of_driver_plan,ifelse(duration_of_driver_plan<90,90,duration_of_driver_plan)),
- case = ifelse(!is.na(end_time),ifelse(start_time<prev_date_monthly & end_time>=insert_date_monthly,1,ifelse(start_time<insert_date_monthly & start_time>=prev_date_monthly & end_time>=prev_date_monthly & end_time<insert_date_monthly,2,ifelse(end_time>=insert_date_monthly,3,4))),ifelse(start_time<prev_date_monthly,5,6)),
- dp_gmv = duration_in_given_month*GMV/7, dp_gmv_pre_insurance = duration_in_given_month*GMV_pre_insurance/7, dp_booking_commission = duration_in_given_month*Commission/7,dp_insurance = duration_in_given_month*Insurance/7,dp_payout = duration_in_given_month*Payout/7)
- KPIS_monthly <- bookings_monthly %>% summarise(GMV_less_insurance = sum(dp_gmv_pre_insurance),booking_commission = sum(dp_booking_commission),Insurance = sum(dp_insurance),Payout = sum(dp_payout),GMV = sum(dp_gmv),date = prev_date_monthly %>% format("%b %y"))}
- #Weekly KPIS
- {insert_date_weekly <- Sys.Date()+1
- prev_date_weekly <- (Sys.Date()-days((Sys.Date() %>% format("%u")))) %>% format("%Y-%m-%d") %>% as.Date()
- bookings_weekly <- bookings
- bookings_weekly$d <- (100-bookings_weekly$d)/100
- bookings_weekly <- bookings_weekly %>% mutate(GMV = ((b-i)*d+i),
- GMV_pre_insurance = (b-i)*d,
- Commission = (b-i-o)*d,
- Payout = o*d, Insurance = i)
- bookings_weekly$start_time <- fastPOSIXct(bookings_weekly$start_time) %>% format("%Y-%m-%d") %>% as.Date()
- bookings_weekly$end_time <- fastPOSIXct(bookings_weekly$end_time) %>% format("%Y-%m-%d") %>% as.Date()
- driver_cohorts <- bookings_weekly %>% group_by(driver_id) %>% summarise(cohort = min(start_time) %>% format("%Y %m"), cohort_year = min(start_time) %>% format("%Y"), cohort_start = min(start_time) %>% format("%Y-%m-01") %>% as.Date("%Y-%m-%d"))
- bookings_weekly <- bookings_weekly %>% filter((start_time<prev_date_weekly & end_time>=insert_date_weekly) | (start_time>=prev_date_weekly & end_time<insert_date_weekly) | (start_time<prev_date_weekly & end_time<insert_date_weekly & end_time>=prev_date_weekly) | (start_time>=prev_date_weekly & start_time<insert_date_weekly & end_time>=insert_date_weekly) |(is.na(end_time) & start_time<insert_date_weekly) ) %>%
- mutate(duration_of_driver_plan = ifelse(!is.na(end_time),(end_time-start_time),(insert_date_weekly-start_time)),
- duration_to_date = ifelse((start_time>insert_date_weekly) | is.na(end_time), insert_date_weekly-start_time, end_time-start_time),
- duration_in_given_month = ifelse(!is.na(end_time), ifelse(start_time<prev_date_weekly & end_time>=insert_date_weekly,(insert_date_weekly-prev_date_weekly) %>% as.numeric(),ifelse(start_time<insert_date_weekly & start_time>=prev_date_weekly & end_time>=prev_date_weekly & end_time<insert_date_weekly,end_time-start_time, ifelse(end_time>=insert_date_weekly,insert_date_weekly-start_time-1,end_time-prev_date_weekly+1))), ifelse(start_time<prev_date_weekly,insert_date_weekly-prev_date_weekly,insert_date_weekly-start_time-1)),
- duration_projection = ifelse(!is.na(end_time),duration_of_driver_plan,ifelse(duration_of_driver_plan<90,90,duration_of_driver_plan)),
- case = ifelse(!is.na(end_time),ifelse(start_time<prev_date_weekly & end_time>=insert_date_weekly,1,ifelse(start_time<insert_date_weekly & start_time>=prev_date_weekly & end_time>=prev_date_weekly & end_time<insert_date_weekly,2,ifelse(end_time>=insert_date_weekly,3,4))),ifelse(start_time<prev_date_weekly,5,6)),
- dp_gmv = duration_in_given_month*GMV/7, dp_gmv_pre_insurance = duration_in_given_month*GMV_pre_insurance/7, dp_booking_commission = duration_in_given_month*Commission/7,dp_insurance = duration_in_given_month*Insurance/7,dp_payout = duration_in_given_month*Payout/7)
- KPIS_weekly <- bookings_weekly %>% summarise(GMV_less_insurance = sum(dp_gmv_pre_insurance),booking_commission = sum(dp_booking_commission),Insurance = sum(dp_insurance),Payout = sum(dp_payout),GMV = sum(dp_gmv),date = prev_date_weekly %>% format("%b %y"))}
- #Live weekly KPIS
- insert_date_weekly <- Sys.Date()+1
- prev_date_weekly <- (Sys.Date()-days((Sys.Date() %>% format("%u")))) %>% format("%Y-%m-%d") %>% as.Date()
- bookings_weekly <- bookings
- bookings_weekly$d <- (100-bookings_weekly$d)/100
- bookings_weekly <- bookings_weekly %>% mutate(GMV = ((b-i)*d+i),
- GMV_pre_insurance = (b-i)*d,
- Commission = (b-i-o)*d,
- Payout = o*d, Insurance = i, start_time2 = start_time)
- bookings_weekly$start_time <- fastPOSIXct(bookings_weekly$start_time) %>% format("%Y-%m-%d") %>% as.Date()
- bookings_weekly$end_time <- fastPOSIXct(bookings_weekly$end_time) %>% format("%Y-%m-%d") %>% as.Date()
- driver_cohorts <- bookings_weekly %>% group_by(driver_id) %>% summarise(cohort = min(start_time) %>% format("%Y %m"), cohort_year = min(start_time) %>% format("%Y"), cohort_start = min(start_time) %>% format("%Y-%m-01") %>% as.Date("%Y-%m-%d"))
- bookings_weekly <- bookings_weekly %>% filter((start_time<prev_date_weekly & end_time>=insert_date_weekly) | (start_time>=prev_date_weekly & end_time<insert_date_weekly) | (start_time<prev_date_weekly & end_time<insert_date_weekly & end_time>=prev_date_weekly) | (start_time>=prev_date_weekly & start_time<insert_date_weekly & end_time>=insert_date_weekly) |(is.na(end_time) & start_time<insert_date_weekly) ) %>%
- mutate(duration_of_driver_plan = ifelse(!is.na(end_time),(end_time-start_time),(insert_date_weekly-start_time)),
- duration_to_date = ifelse((start_time>insert_date_weekly) | is.na(end_time), insert_date_weekly-start_time, end_time-start_time),
- duration_in_given_month = ifelse(!is.na(end_time), ifelse(start_time<prev_date_weekly & end_time>=insert_date_weekly,(insert_date_weekly-prev_date_weekly) %>% as.numeric(),ifelse(start_time<insert_date_weekly & start_time>=prev_date_weekly & end_time>=prev_date_weekly & end_time<insert_date_weekly,end_time-start_time, ifelse(end_time>=insert_date_weekly,insert_date_weekly-start_time-1,end_time-prev_date_weekly+1))), ifelse(start_time<prev_date_weekly,insert_date_weekly-prev_date_weekly,insert_date_weekly-start_time-1)),
- duration_projection = ifelse(!is.na(end_time),duration_of_driver_plan,ifelse(duration_of_driver_plan<90,90,duration_of_driver_plan)),
- case = ifelse(!is.na(end_time),ifelse(start_time<prev_date_weekly & end_time>=insert_date_weekly,1,ifelse(start_time<insert_date_weekly & start_time>=prev_date_weekly & end_time>=prev_date_weekly & end_time<insert_date_weekly,2,ifelse(end_time>=insert_date_weekly,3,4))),ifelse(start_time<prev_date_weekly,5,6)),
- dp_gmv = duration_in_given_month*GMV/7, dp_gmv_pre_insurance = duration_in_given_month*GMV_pre_insurance/7, dp_booking_commission = duration_in_given_month*Commission/7,dp_insurance = duration_in_given_month*Insurance/7,dp_payout = duration_in_given_month*Payout/7)
- KPIS_weekly <- bookings_weekly %>% summarise(GMV_less_insurance = sum(dp_gmv_pre_insurance),booking_commission = sum(dp_booking_commission),Insurance = sum(dp_insurance),Payout = sum(dp_payout),GMV = sum(dp_gmv),date = prev_date_weekly %>% format("%b %y"))
- x2 <- bookings_monthly2 %>% select(start_time2,end_time,GMV,GMV_pre_insurance,Commission,Payout,Insurance,duration_in_given_month)
- agent <- dbGetQuery(con, "
- select bookings.id as booking_id,bookings.booked_by_id,partners.first_name,partners.last_name,bookings.driver_id, driver_plans.start_time,
- case when driver_plans.end_time = 'infinity' then NULL else driver_plans.end_time end, driver_plans.created_at from driver_plans
- left join bookings on driver_plans.booking_id = bookings.id
- left join partners on bookings.booked_by_id = partners.id
- where driver_plans.state = 'booked' and bookings.fleet_organisation_id is null") %>% as.tibble() %>% filter(as.Date(created_at)==Sys.Date()) %>% arrange(desc(created_at)) %>% mutate('Booked by' = ifelse(is.na(first_name),"?",paste(first_name,last_name)))
- #install.packages("remotes")
- #remotes::install_github("rstats-db/RPostgres")
- ui <- dashboardPage(skin = "green",
- dashboardHeader(title = "Drover Dashboard"),
- #Dashboard Sidebar
- dashboardSidebar(
- sidebarMenu(
- menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
- menuItem("Demand", tabName = "demand", icon = icon("address-card-o")),
- menuItem("Supply", tabName = "supply"),
- #menuItem("New Bookings Today", tabName = "newbookingstoday"),
- menuItem("Cohort Analysis", tabName = "cohorts"),
- menuItem("Vehicles Analysis", tabName = "vehicles"))
- ),
- dashboardBody
- (
- tabItems(
- #Dashboard
- tabItem(tabName = "dashboard",
- fluidRow(box(h1("Current time:",textOutput("currentTime", container = span))),box(infoBoxOutput("gmv_runrate_per_second"))),
- #fluidRow(box(h2("Live GMV Numbers")),box(h2("Live Supply and Demand numbers"))),
- fluidRow(box(valueBoxOutput("gmv_per_second",width=3),valueBoxOutput("GMV_this_month",width=3),valueBoxOutput("GMV_this_week",width=3), #valueBoxOutput("commission_this_month"),
- valueBoxOutput("bookingsrightnow",width=3),width=12)),
- fluidRow(box(radioButtons("metric_choice","Select a KPI",choices = list("GMV"=1,"Insurance"=2),selected=1,inline=TRUE),
- dygraphOutput("time_series1"),width=12)),
- #valueBoxOutput("utilisation_right_now",width=3),width=12),
- fluidRow(
- box(radioButtons("cbb","Select a metric",choices = list("Count" = 1,"Average duration (to date)" = 2),selected = 1,inline = TRUE),
- plotOutput("current_bookings_breakdown1")),#box(plotOutput("current_bookings_breakdown2")),
- box(h2("New bookings today"),dataTableOutput("bookingstoday"))),
- #bubblesOutput("bubbles"))),
- #box(valueBoxOutput("gmv_per_second_weekly")),
- fluidRow(
- box(h2("Breakdown of current bookings:"),
- radioButtons("dog","Group by",choices = list("All" = 5, "Manufacturer" = 1, "Year" = 2, "Uber Type" = 3, "Manufacturer and Uber type" = 4), selected = 5, inline = TRUE),
- dataTableOutput("vehiclesbreakdown")),
- fluidRow(box(bubblesOutput("trybubbles")))
- )),
- tabItem(tabName = "demand",
- fluidRow(box(h1("Demand driven data"),valueBoxOutput("new_drivers_this_month"),valueBoxOutput("new_drivers_today")),
- box(h2("Drivers at risk of churning"),h4("Drivers whose current booking will end before or after n days and are not down to renew"),
- dataTableOutput("drivers_at_risk_of_churning"))),
- fluidRow(box(h2("New drivers acquired today"),dataTableOutput("new_drivers_today_table")),
- fluidRow(box(h2("Driver acquisition historically"),
- #dateInput("date_conceived","How many days back would you like to look at?",min=as.Date("2016-01-01"),max = Sys.Date(),value=28,format = "%b %y"),
- radioButtons("date_conceived","Time period",choices = list("Last Month" = 28,"Last 3 months" = 84, "Last Year" = 340),selected = 28,inline = TRUE),
- plotOutput("drivers_conception"))),
- box(h2("Bookings which are earning us negative commission"),dataTableOutput("dodgybookings"),width=12))),
- tabItem(tabName = "supply",
- fluidRow(box(h1("Supply driven data"),valueBoxOutput("excess_vehicles"))),
- fluidRow(box(h2("Breakdown of suppliers"),dataTableOutput("owner_breakdown")),
- box(h2("The following vehicles are not on hire and are not booked onto any future bookings"),
- radioButtons("group1","What would you like to group by?",choices = list("All"=5,"Supplier"=1,"Vehicle Make"=2,"Vehicle Model"=3,"Year"=4),selected=3,inline=TRUE),
- bubblesOutput("excess_vehicles_table")))
- ),
- tabItem(tabName = "cohorts",
- fluidRow(box(plotOutput("cohorts_LTV")),box(plotOutput("cohorts_LTV2"))),
- fluidRow(box(h2("From which cohorts are our current active drivers from?"),plotOutput("active_cohorts")),
- box(h2("Number of drivers that joined us in each month"),plotOutput("cohorts")))
- ),
- tabItem(tabName = "vehicles",
- fluidRow(box(dataTableOutput("vehicle_kpis"), radioButtons("com_or_gmv","Select Commission or GMV",choices = list("GMV" = 1, "Commission" = 2), selected = 1, inline = TRUE),
- bubblesOutput("vehicle_kpis_bubble")),
- box(dataTableOutput("vehicle_kpis2"), radioButtons("com_or_gmv2","Select Commission or GMV",choices = list("GMV" = 1, "Commission" = 2), selected = 1, inline = TRUE),
- bubblesOutput("vehicle_kpis_bubble2"))))
- )
- #box(valueBoxOutput("excess_vehicles"),valueBoxOutput("bookingsrightnow")),
- )
- )
- server <- function(input, output, session) {
- #Dashboard tab
- output$currentTime <- renderText({
- invalidateLater(1000, session)
- format(Sys.time() %>% format("%A %d %B %H:%M:%S"))
- })
- output$commission_this_month <- renderValueBox({
- invalidateLater(10000)
- valueBox((dollar_format("£")(KPIS_monthly$booking_commission)),"Commission this month (to date)", icon = icon("thumbs-up"), color = "green")
- })
- output$GMV_this_month <- renderValueBox({
- invalidateLater(10000)
- valueBox((dollar_format("£")(KPIS_monthly$GMV)),"GMV so far this month", icon = icon("thumbs-up"), color = "green")
- })
- output$GMV_this_week <- renderValueBox({
- invalidateLater(10000)
- valueBox((dollar_format("£")(KPIS_weekly$GMV)),"GMV so far this week", icon = icon("thumbs-up"), color = "green")
- })
- output$gmv_per_second <- renderValueBox({
- invalidateLater(500)
- y <- x %>% mutate(seconds = ((duration_in_given_month-1)*24*60*60)+(Sys.time() %>% format("%H") %>% as.numeric())*3600+(Sys.time() %>% format("%M") %>% as.numeric())*60+(Sys.time() %>% format("%S") %>% as.numeric()), x1 = (GMV*seconds/(24*7*60*60)) %>%round(2)) %>% mutate(seconds = ((duration_in_given_month-1)*24*60*60)+(Sys.time() %>% format("%H") %>% as.numeric())*3600+(Sys.time() %>% format("%M") %>% as.numeric())*60+(Sys.time() %>% format("%S") %>% as.numeric()), x1 = GMV*seconds/(24*7*60*60)) %>% summarise(sum(as.numeric(x1)))
- y <- dollar_format("£")(y[[1]])
- valueBox(y,"GMV this month to the nearest second")
- })
- output$gmv_per_second_weekly <- renderValueBox({
- invalidateLater(500)
- y1 <- x1 %>% mutate(seconds = ((duration_in_given_month-1)*24*60*60)+(Sys.time() %>% format("%H") %>% as.numeric())*3600+(Sys.time() %>% format("%M") %>% as.numeric())*60+(Sys.time() %>% format("%S") %>% as.numeric()), x1 = (GMV*seconds/(24*7*60*60)) %>%round(2)) %>% mutate(seconds = ((duration_in_given_month-1)*24*60*60)+(Sys.time() %>% format("%H") %>% as.numeric())*3600+(Sys.time() %>% format("%M") %>% as.numeric())*60+(Sys.time() %>% format("%S") %>% as.numeric()), x1 = GMV*seconds/(24*7*60*60)) %>% summarise(sum(as.numeric(x1)))
- y1 <- dollar_format("£")(y1[[1]])
- valueBox(y,"GMV this month to the nearest second")
- })
- output$gmv_runrate_per_second <- renderInfoBox({
- invalidateLater(500)
- y <- x %>% mutate(seconds = ((duration_in_given_month-1)*24*60*60)+(Sys.time() %>% format("%H") %>% as.numeric())*3600+(Sys.time() %>% format("%M") %>% as.numeric())*60+(Sys.time() %>% format("%S") %>% as.numeric()), x1 = (GMV*seconds/(24*7*60*60)) %>%round(2)) %>% mutate(seconds = ((duration_in_given_month-1)*24*60*60)+(Sys.time() %>% format("%H") %>% as.numeric())*3600+(Sys.time() %>% format("%M") %>% as.numeric())*60+(Sys.time() %>% format("%S") %>% as.numeric()), x1 = GMV*seconds/(24*7*60*60)) %>% summarise(sum(as.numeric(x1)))
- y <- dollar_format("£")(y[[1]]*12)
- infoBox(h1(y),"Annual GMV")
- })
- output$bookingsrightnow <- renderValueBox({
- invalidateLater(1000)
- valueBox(bookings %>% filter((end_time>=Sys.time() | is.na(end_time)) & start_time<=Sys.time()) %>% nrow(),"Bookings occurring right now",icon = icon("thumbs-up"),color = "green")})
- output$utilisation_right_now <- renderValueBox({
- valueBox((nrow(vehicles_on_hire) / nrow(vehicles_available)) %>% percent(), "Utilisation", color = "red")
- })
- output$excess_vehicles <- renderValueBox({valueBox(vehicles_enabled %>% filter(is.na(booking_id)) %>% nrow(),"Vehicles available to be booked")})
- output$excess_vehicles_table <- renderBubbles({
- v <- vehicles_enabled %>% filter(is.na(booking_id)) %>% select(vehicle_id,supplier,vehicle_make,vehicle_model,year,licence_plate)
- if (input$group1==1) {
- a <- v %>% group_by(supplier) %>% summarise(count = n()) %>% arrange(desc(count))
- plot <- bubbles(a$count,a$supplier)
- }
- if (input$group1==2) {
- a <- v %>% group_by(vehicle_make) %>% summarise(count = n()) %>% arrange(desc(count))
- plot <- bubbles(a$count,a$vehicle_make)
- }
- if (input$group1==3) {
- a <- v %>% group_by(vehicle_model) %>% summarise(count = n()) %>% arrange(desc(count))
- plot <- bubbles(a$count,a$vehicle_model)
- }
- if (input$group1==4) {
- a <- v %>% group_by(year) %>% summarise(count = n()) %>% arrange(desc(count))
- plot <- bubbles(a$count,a$year)
- }
- #if (input$group1==2) {v <- v %>% group_by(vehicle_make) %>% summarise(count = n()) %>% arrange(desc(count))}
- #if (input$group1==3) {v <- v %>% group_by(vehicle_model) %>% summarise(count = n()) %>% arrange(desc(count))}
- #if (input$group1==4) {v <- v %>% group_by(year) %>% summarise(count = n()) %>% arrange(desc(count))}
- plot
- })
- output$bookingstoday <- renderDataTable({
- invalidateLater(60000)
- x <- agent
- x$created_at <- as.character(x$created_at)
- x$start_time <- as.character(x$start_time)
- x$end_time <- ifelse(is.na(x$end_time),"Rolling",as.character(x$end_time))
- x <- x[,c(1,5:9)]
- colnames(x) <- c("Booking Id","Driver Id","Start Time","End Time","Booked at","Booked by")
- print(x)})
- output$vehiclesbreakdown <- renderDataTable({
- invalidateLater(1000000)
- if (input$dog==1) {
- x <- vehicles_on_hire[,-1] %>% group_by(Manufacturer = vehicle_make) %>% summarise(Count = n(), Average_List_Price = mean(list_price,na.rm=T))
- colnames(x) <- c("Manufacturer","Count","Average List Price")
- }
- if (input$dog==2) {
- x <- vehicles_on_hire[,-1] %>% group_by(Year = year) %>% summarise(Count = n(), Average_List_Price = mean(list_price,na.rm=T))
- colnames(x) <- c("Year","Count","Average List Price")
- }
- if (input$dog==3) {
- x <- vehicles_on_hire[,-1] %>% group_by('Uber Type' = sub_type) %>% summarise(Count = n(), Average_List_Price = mean(list_price,na.rm=T))
- colnames(x) <- c("Uber Type","Count","Average List Price")
- }
- if (input$dog==4) {
- x <- vehicles_on_hire[,-1] %>% group_by(Manufacturer = vehicle_make,'Uber Type' = sub_type) %>% summarise(Count = n(), Average_List_Price = mean(list_price,na.rm=T))
- colnames(x) <- c("Manufacturer","Uber Type","Count","Average List Price")
- }
- if (input$dog==5) {
- x <- vehicles_on_hire[,-1] %>% summarise(Count = n(), Average_List_Price = mean(list_price,na.rm=T))
- colnames(x) <- c("Count","Average List Price")
- }
- x$'Average List Price' <- dollar_format("£")(x$'Average List Price')
- print(x)
- })
- # output$bubbles <- renderBubbles({
- # if (input$dog==1) {
- # x <- vehicles_on_hire[,-1] %>% group_by(Manufacturer = vehicle_make) %>% summarise(Count = n(), Average_List_Price = mean(list_price,na.rm=T))
- # bubbles(x$Count,x$Manufacturer)
- # }
- # if (input$dog==2) {
- # x <- vehicles_on_hire[,-1] %>% group_by(Year = year) %>% summarise(Count = n(), Average_List_Price = mean(list_price,na.rm=T))
- # bubbles(x$Count,x$Year)
- # }
- # if (input$dog==3) {
- # x <- vehicles_on_hire[,-1] %>% group_by('Uber Type' = sub_type) %>% summarise(Count = n(), Average_List_Price = mean(list_price,na.rm=T))
- # bubbles(x$Count,x$'Uber Type')
- # }
- #if (input$dog==4) {x <- vehicles_on_hire[,-1] %>% group_by(Manufacturer = vehicle_make,'Uber Type' = sub_type) %>% summarise(Count = n(), Average_List_Price = mean(list_price,na.rm=T))}
- # })
- output$new_drivers_this_month <- renderValueBox({
- valueBox(cohorts %>% filter(cohort==Sys.Date() %>% format("%Y %m")) %>% nrow(),"New drivers this month")
- })
- output$new_drivers_today <- renderValueBox({
- valueBox(cohorts %>% filter(time_of_conception %>% as.Date()==Sys.Date()) %>% nrow(),"New drivers today")
- })
- output$cohorts <- renderPlot({
- c <- cohorts %>% group_by(cohort,cohort_start) %>% summarise(count = n()) %>% mutate(Cohort = format(cohort_start,"%b %y"))
- ggplot(c, aes(reorder(Cohort,cohort_start),count))+geom_bar(stat = 'identity', fill = "green4")+theme_classic()+geom_text(aes(label = count),vjust=-0.5)+labs(x = "Cohort")+theme(axis.text.y = element_blank(),axis.line = element_blank(), axis.ticks.x = element_blank(),axis.title.y = element_blank(), axis.ticks.y = element_blank())
- })
- output$new_drivers_today_table <- renderDataTable({
- a <- cohorts %>% filter(time_of_conception %>% as.Date()==Sys.Date())
- a <- left_join(a,agent,by="driver_id") %>% arrange(desc(time_of_conception)) %>% select('Booked by',driver_id,time_of_conception,start_time,end_time,booking_id)
- a$time_of_conception <- as.character(a$time_of_conception)
- a$start_time <- as.character(a$start_time)
- a$end_time <- as.character(a$end_time)
- a
- })
- output$dodgybookings <- renderDataTable({
- invalidateLater(20000)
- d <- bookings
- d <- d %>% mutate(GMV = ((b-i)*d+i),
- GMV_pre_insurance = (b-i)*d,
- Commission = (b-i-o)*d,
- Payout = o*d, Insurance = i)
- #d$end_time <- ifelse(d$end_time>'2050-01-01',"Rolling",d$end_time %>% as.Date())
- d <- d %>% filter(start_time<=Sys.time(),is.na(end_time) | end_time>=Sys.time(),end_time<'2050-01-01') %>% filter(Commission<0)
- d$end_time <- ifelse(is.na(d$end_time),"Rolling",d$end_time %>% as.character())
- d$d <- (d$d) %>% percent()
- d$created_at <- as.character(d$created_at)
- d$start_time <- as.character(d$start_time)
- d$b <- dollar_format("£")(d$b)
- d$i <- dollar_format("£")(d$i)
- d$o <- dollar_format("£")(d$o)
- d$GMV <- dollar_format("£")(d$GMV)
- #d$Commission <- dollar_format("£")(d$Commission)
- d$Payout <- dollar_format("£")(d$Payout)
- colnames(d) <- c("Driver Id","Start Time","End Time","Booked at","Booking Amount","Insurance","Discount","Owner Payout","GMV","GMV Pre Insurance","Commission","Payout","Insurance")
- print(d[,-c(13,10)])
- })
- output$owner_breakdown <- renderDataTable({
- vehicles_enabled %>% group_by(supplier) %>% summarise('Vehicles on Platform' = n(),'Vehicles in Bookings' = sum(!is.na(booking_id)),Utilisation = (sum(!is.na(booking_id))/n()) %>% percent()) %>% arrange(desc(`Vehicles in Bookings`))
- })
- output$drivers_at_risk_of_churning <- renderDataTable({
- renew <- bookings %>% filter(end_time>Sys.time() | is.na(end_time)) %>% group_by(driver_id) %>% summarise(count = n(), end = min(end_time)) %>% select(c(1,3))
- renew <- renew %>% arrange(end)
- renew$end <- as.character(renew$end)
- colnames(renew) <- c("Driver Id","Current booking will end on:")
- print(renew)
- })
- output$drivers_conception <- renderPlot({
- cohorts %>% filter(time_of_conception>as.Date('2017-01-01')) %>% group_by(week_of_conception = format(time_of_conception,"%U")) %>% summarise(count = n(), week_starting = min(format(time_of_conception,"%Y-%m-%d")) %>% as.Date()) %>% filter(week_starting>=Sys.Date()-days(input$date_conceived)) %>% ggplot(aes(reorder(week_of_conception,week_starting),count))+geom_bar(stat = 'identity', fill = "green4")+theme_minimal()+labs(x = "Week number", y = "Count")
- })
- #output$dodgybookingsloss <- renderValueBox(valueBox(sum(d$'Commission'),"Weekly amount lost due to the following bookings:", color = "red"))
- output$cohorts_LTV <- renderPlot({
- vehicles <- dbGetQuery(con,"select vehicles.id as vehicle_id, vehicle_make, year, sub_type,
- case when companies.name is null then concat(partners.first_name,' ',partners.last_name,'*') else companies.name end as Supplier
- from vehicles
- left join companies on companies.partner_id = vehicles.owner_id
- left join partners on vehicles.owner_id = partners.id") %>% as.tibble()
- #bookings <- dbGetQuery(con, bookingsquery) %>% as.tibble()
- bookings$d <- (100-bookings$d)/100
- bookings <- bookings %>% mutate(GMV = ((b-i)*d+i)/100,
- GMV_pre_insurance = (b-i)*d/100,
- Commission = (b-i-o)*d/100,
- Payout = o*d/100, Insurance = i/100)
- bookings <- bookings %>%
- mutate(duration_to_date = ifelse((end_time>Sys.Date()) | is.na(end_time), Sys.Date()-as.Date(start_time), as.Date(end_time)-as.Date(start_time)),
- dp_gmv = duration_to_date*GMV/7,
- dp_gmv_pre_insurance = duration_to_date*GMV_pre_insurance/7, dp_booking_commission = duration_to_date*Commission/7,dp_insurance = duration_to_date*Insurance/7,dp_payout = duration_to_date*Payout/7)
- #KPIS <- bookings %>% summarise(GMV_less_insurance = sum(dp_gmv_pre_insurance)/100,booking_commission = sum(dp_booking_commission)/100,Insurance = sum(dp_insurance)/100,Payout = sum(dp_payout)/100,GMV = sum(dp_gmv)/100,date = prev_date %>% format("%b %y")) %>% print()
- drivers <- bookings %>% group_by(driver_id) %>% summarise(cohort = format(min(as.Date(start_time)),"%Y %m"),cohort_start = format(min(as.Date(start_time)),"%Y-%m-01") %>% as.Date(),driver_plan_count = n(),driver_lifetime_duration = sum(duration_to_date), gmv_to_date = sum(dp_gmv), booking_commission_to_date = sum(dp_booking_commission) %>% round(2))
- drivers_kpis <- drivers %>% group_by(cohort,cohort_start) %>%
- summarise(size = n(),gmv = sum(gmv_to_date),commission = sum(booking_commission_to_date),
- duration = mean(driver_lifetime_duration), LTV_gmv = gmv/size, LTV_commission = commission/size) %>% as.data.frame()
- vehicle_kpis <- left_join(bookings %>% filter(start_time>as.Date('2016-07-01')),vehicles,by="vehicle_id") %>% group_by(vehicle_id,vehicle_make,year,sub_type,supplier) %>%
- summarise(bookings = n(),gmv = sum(dp_gmv),commission = sum(dp_booking_commission), commission_rate = percent(commission/gmv), days_hired = sum(duration_to_date))
- ggplot(drivers_kpis, aes(reorder(cohort,cohort_start),LTV_commission))+geom_bar(stat = 'identity',fill = "green4")+theme_classic()+geom_text(aes(label=dollar_format("£")(LTV_commission)),vjust=-0.5)+
- theme(axis.text.y = element_blank(),axis.line = element_blank(), axis.ticks.x = element_blank(),axis.title.y = element_blank(), axis.ticks.y = element_blank())+labs(x = "Cohort",title = "LTV Commission")
- #
- })
- output$cohorts_LTV2 <- renderPlot({
- ggplot(drivers_kpis, aes(reorder(cohort,cohort_start),LTV_gmv))+geom_bar(stat = 'identity',fill = "green4")+theme_classic()+geom_text(aes(label=dollar_format("£")(LTV_gmv)),vjust=-0.5)+
- theme(axis.text.y = element_blank(),axis.line = element_blank(), axis.ticks.x = element_blank(),axis.title.y = element_blank(), axis.ticks.y = element_blank())+labs(x = "Cohort",title = "LTV GMV")
- })
- output$vehicle_kpis <- renderDataTable({
- vehicle_kpis %>% group_by(sub_type) %>% summarise('Avg Booking Duration' = paste(mean(days_hired) %>% round(),"days"),'# Bookings' = n(), GMV_per_day_on_hire = dollar_format("£")(sum(gmv)/sum(days_hired)), 'Commission/day' = dollar_format("£")(sum(commission)/sum(days_hired)), 'Commission %' = ((sum(commission)/sum(days_hired))/(sum(gmv)/sum(days_hired))) %>% percent())
- })
- output$vehicle_kpis2 <- renderDataTable({
- vehicle_kpis %>% group_by(year) %>% summarise('Avg Booking Duration' = paste(mean(days_hired) %>% round(),"days"),'# Bookings' = n(), GMV_per_day_on_hire = dollar_format("£")(sum(gmv)/sum(days_hired)), 'Commission/day' = dollar_format("£")(sum(commission)/sum(days_hired)), 'Commission %' = ((sum(commission)/sum(days_hired))/(sum(gmv)/sum(days_hired))) %>% percent())
- })
- output$vehicle_kpis_bubble <- renderBubbles({
- f <- vehicle_kpis %>% group_by(sub_type) %>% summarise('Avg Booking Duration' = paste(mean(days_hired) %>% round(),"days"),'# Bookings' = n(), GMV_per_day_on_hire = (sum(gmv)/sum(days_hired)), 'Commission/day' = (sum(commission)/sum(days_hired)), 'Commission %' = ((sum(commission)/sum(days_hired))/(sum(gmv)/sum(days_hired))) %>% percent())
- if (input$com_or_gmv==1) {sub_plot <- bubbles(f$GMV_per_day_on_hire,paste(f$sub_type,':',dollar_format("£")(f$GMV_per_day_on_hire)))}
- if (input$com_or_gmv==2) {sub_plot <- bubbles(f$`Commission/day`,paste(f$sub_type,':',dollar_format("£")(f$`Commission/day`)))}
- sub_plot
- })
- output$vehicle_kpis_bubble2 <- renderBubbles({
- g <- vehicle_kpis %>% group_by(sub_type) %>% summarise('Avg Booking Duration' = paste(mean(days_hired) %>% round(),"days"),'# Bookings' = n(), GMV_per_day_on_hire = (sum(gmv)/sum(days_hired)), 'Commission/day' = (sum(commission)/sum(days_hired)), 'Commission %' = ((sum(commission)/sum(days_hired))/(sum(gmv)/sum(days_hired))) %>% percent())
- if (input$com_or_gmv2==1) {sub_plot2 <- bubbles(g$GMV_per_day_on_hire,paste(g$sub_type,':',dollar_format("£")(g$GMV_per_day_on_hire)))}
- if (input$com_or_gmv2==2) {sub_plot2 <- bubbles(g$`Commission/day`,paste(g$sub_type,':',dollar_format("£")(g$`Commission/day`)))}
- sub_plot2
- })
- output$active_cohorts <- renderPlot({
- bookings <- dbGetQuery(con, bookingsquery) %>% as.tibble()
- active_drivers <- bookings %>% filter(start_time<=Sys.time(),is.na(end_time) | end_time>Sys.time()) %>% select(3) %>%
- left_join(drivers,by="driver_id") %>% mutate(cohort_bucket = ifelse(format(cohort_start,"%Y") %>% as.numeric()==2016,2016,
- ifelse(format(cohort_start,"%Y")==2017 & cohort_start<'2017-09-01',"Jan-Aug 17",format(cohort_start,"%b %y"))),
- cohort_bucket_start = ifelse(cohort_bucket==2016,as.Date('2016-01-01'),
- ifelse(cohort_bucket=="Jan-Aug 17",as.Date('2017-08-01'),cohort_start))) %>%
- group_by(cohort_bucket,cohort_bucket_start) %>% summarise(count = n(), avg_lifetime = mean(driver_lifetime_duration))
- ggplot(active_drivers, aes(x = reorder(cohort_bucket,cohort_bucket_start),y = count))+geom_bar(stat = 'identity', fill = "green4")+theme_classic()+geom_text(aes(label=count),vjust=-0.5, size= 6)+
- theme(axis.text.y = element_blank(),axis.line = element_blank(), axis.ticks.x = element_blank(),axis.title.y = element_blank(), axis.ticks.y = element_blank(), axis.text.x = element_text(size = 12), axis.title.x = element_text(size = 14))+labs(x = "Cohort Group")
- })
- output$current_bookings_breakdown1 <- renderPlot({
- if (input$cbb==1) {cbbplot <- ggplot(current_bookings, aes(x = factor(1), y = count, fill = type, group = type))+geom_bar(stat = 'identity')+
- geom_text(aes(label = paste(type,':',count),y = posy, x = 1.85, size = 6))+scale_fill_manual(values = c("green4","green1"))+
- theme_void()+coord_polar(theta = "y")+theme(legend.position = "none")}
- if (input$cbb==2) {cbbplot <- ggplot(current_bookings, aes(type,avg_duration))+geom_bar(stat = 'identity',fill="green3",width = 0.35)+geom_text(aes(label=paste(round(avg_duration),"days")),vjust=-0.5)+theme_classic()+
- theme(axis.text.y = element_blank(),axis.ticks.x = element_blank(),axis.title.y = element_blank(), axis.ticks.y = element_blank(), axis.text.x = element_text(size = 12), axis.title.x = element_blank())}
- cbbplot
- })
- output$trybubbles <- renderBubbles({
- drivers <- bookings %>% group_by(driver_id) %>% summarise(cohort = format(min(as.Date(start_time)),"%Y %m"),cohort_start = format(min(as.Date(start_time)),"%Y-%m-01") %>% as.Date())
- b <- drivers %>% group_by(cohort) %>% summarise(count = n())
- bubbles(b$count,b$cohort)
- })
- # output$current_bookings_breakdown2 <- renderPlot({
- # ggplot(current_bookings, aes(type,avg_duration))+geom_bar(stat = 'identity',fill="green3",width = 0.35)+geom_text(aes(label=paste(round(avg_duration),"days")),vjust=-0.5)+theme_classic()+
- # theme(axis.text.y = element_blank(),axis.ticks.x = element_blank(),axis.title.y = element_blank(), axis.ticks.y = element_blank(), axis.text.x = element_text(size = 12), axis.title.x = element_blank())
- #})
- output$time_series1 <- renderDygraph({
- if (input$metric_choice==1) {y <- ts1 %>% filter(Metric=="GMV") %>% select(date2,Amount) %>% filter(date2>=as.Date('2017-01-01'))}
- if (input$metric_choice==2) {y <- ts1 %>% filter(Metric=="Insurance") %>% select(date2,Amount) %>% filter(date2>=as.Date('2017-01-01'))}
- dygraph(as.xts(y$Amount,order.by = y$date2))
- })
- }
- # Run the application
- shinyApp(ui = ui, server = server)
Add Comment
Please, Sign In to add comment