App runs locally, but disconnects from server when file is uploaded using fileInput() with nothing in error logs

764 views
Skip to first unread message

aaa...@georgetown.edu

unread,
Jul 20, 2017, 3:24:39 PM7/20/17
to shinyapps.io Users

I created two shinyapps that allow the user to upload an excel spreadsheet and use an interface to create various types of graphs. Both work locally - and the first app of the two below works fine on shinyapps.io. The second launches fine on shinyapps.io (the user interface displays with no issue), but when I uploaded the attached spreadsheet, the screen goes grey and it says the app was disconnected from the server. There is nothing informative in the error log. I don't think the problem is file size or memory usage, as the first app works fine with the same file uploaded. I have increased the startup timeout to the maximum, but this has not helped. The only major difference between the two apps is that the second app (which isn't working) has a global.R file which creates some global objects - but these are fairly small.

Additional Info: When I launch the app that isn't working properly - this error pops up in my browser console "Failed to load resource: the server responded with a status of 404 (HTTP/2.0 404)" - however, like I said, the user interface displays with no problem. When I upload the file, this message pops up in the browser console: "Connection closed. Info: {"type":"close","code":4702,"reason":"Error reading from Shiny","wasClean":true}

(app that works properly on shinyapps.io)"

(app that does not work properly on shinyapps.io)









Server.R for app that isn't running on Shinyapps.io
bookings <- NULL
library(shiny)
library(ggrepel)
library(tidyverse)
library(tidyr)
library(xlsx)
library(zoo)

options(shiny.maxRequestSize = 9*1024^2)


shinyServer(function(input, output) {
  
  
  ## read in file, filter data, standardize to dollar
  room_data <- reactive({
    file1 <- input$file
    if(is.null(file1)){return()}
    bookings <- readxl::read_xlsx(file1$datapath)
    
    
    substrRight <- function(x, n){
      substr(x, nchar(x)-n+1, nchar(x))
    }
    
    #### Filter
    bookings <- dplyr::filter(bookings,BookingStatus != "Cancelled")
    bookings <- dplyr::filter(bookings,Date > input$date_range[1] & Date < input$date_range[2])
    bookings <- dplyr::filter(bookings,LocationCode != "CRC")
    bookings <- dplyr::filter(bookings, ResourceCapacity > 1)
    bookings <- dplyr::filter(bookings, BookedFor != "The Executive Centre")
    
    #### Change Types
    bookings$Date <- as.Date(as.character(bookings$Date))
    bookings$EndDate <- as.Date(as.character(bookings$Date))
    bookings$ResourceCode <- as.character(bookings$ResourceCode)
    bookings$duration <- bookings$TimeEnd - bookings$TimeStart
    bookings$duration <- (as.numeric(bookings$duration)/60)
    bookings$BookedFor <- as.character(bookings$BookedFor)
    bookings$ListedPrice <- as.integer(bookings$ListedPrice)
    bookings$ActualPrice <- as.integer(bookings$ActualPrice)
    bookings$ResourceCapacity <- as.numeric(bookings$ResourceCapacity)
    bookings$Year <- format(bookings$Date,'%Y')
    bookings$Year <- as.numeric(bookings$Year)
    bookings$room_code <- substrRight(bookings$ResourceName,3)
    
    
    ####Clumsy way to filter out tests
    bookings <- mutate(bookings,test_bool = FALSE)
    bookings$test_bool1 <- grepl("test",bookings$BookedFor)
    bookings$test_bool2 <- grepl("Test",bookings$BookedFor)
    bookings$test_bool3 <- grepl("TEST",bookings$BookedFor)
    bookings$test_bool4 <- grepl("test",bookings$ClientRemarks)
    bookings$test_bool5 <- grepl("Test",bookings$ClientRemarks)
    bookings$test_bool6 <- grepl("TEST",bookings$ClientRemarks)
    bookings <- filter(bookings,test_bool1!=TRUE & test_bool2 !=TRUE & test_bool3!=TRUE & test_bool4 !=TRUE & test_bool5!=TRUE & test_bool6 !=TRUE)
    
    droppedvars <- names(bookings) %in% c("test_bool","BookedFor", "CountryCurrencySymbol","CountryAmountFormat","CountryCode","CountryId","CityTimezoneOffset","LocationShortAddress","FloorName","FloorId","ResourcePhoneNumber","ResourceTypeId","ClientRemarks","BookingType","BookingStatus","ShowOnDeviceHost","ShowOnDeviceCompanyName","Memo","test_bool1","test_bool2","test_bool3","test_bool4","test_bool5","test_bool6","CompanyNameForDisplay","CompanyName__1")
    bookings <- bookings[!droppedvars]
    
    ######################################
    ########Standardize Currency##########
    ######################################
    
    countries <- c("AUD","CNY","HKD","INR","IDR","JPY","KRW","MOP","SGD","TWD","NTD")
    
    #### TWD is not included
    
    rates <- c(1.35,6.91,7.8,67.2,13281,109,1155,7.9,1.38,31.2,31.2)
    
    i = 1
    
    for(country in countries)
    {
      bookings$ActualPrice[bookings$CountryCurrencyCode == countries[i]] <- bookings$ActualPrice[bookings$CountryCurrencyCode == countries[i]] / rates[i]
      bookings$ListedPrice[bookings$CountryCurrencyCode == countries[i]] <- bookings$ListedPrice[bookings$CountryCurrencyCode == countries[i]] / rates[i]
      
      i = i + 1
    }
    
    bookings_usd = bookings
    
    ## various filters and added variables
    bookings_usd$price_per_seat <- bookings_usd$ListedPrice/bookings_usd$ResourceCapacity
    bookings_usd$Discount <- bookings_usd$ListedPrice - bookings_usd$ActualPrice
    bookings_usd <- filter(bookings_usd,duration>0)
    bookings_usd$RoomNum <- as.factor(bookings_usd$ResourceCapacity)
    bookings_usd <- bookings_usd[!is.na(bookings_usd$ActualPrice),]
    bookings_usd <- bookings_usd[!is.na(bookings_usd$price_per_seat),]
    bookings_usd <- bookings_usd[!is.na(bookings_usd$ListedPrice),]
    bookings_usd <- filter(bookings_usd, room_code != "08B")
    
   
    
    ##summarize data by room code (i.e. individual room)
    summary <- summarise(group_by(bookings_usd,ResourceName,CountryName),room_revenue = sum(ActualPrice),hours_booked = sum(duration))
    summary$room_code <- substrRight(summary$ResourceName,3)
    summary$LocationCode <- substr(summary$ResourceName,1,3)
    summary <- inner_join(summary,ages, by = "LocationCode")
    summary <- inner_join(summary,workstation_rates, by = "LocationCode")
    summary$Open <- NULL
    summary$today <- NULL

    
    joined <- inner_join(summary,prices_usd,by = c("room_code","LocationCode"))
    joined$price_per_seat_controlled <- joined$price_per_seat / joined$city_factor
    joined <- filter(joined, Capacity > 2)
    joined <- filter(joined, price_per_seat < 15)
    names(joined)[2] <- "Country"
    
    
    joined$Region <- ifelse(joined$City == "Tokyo" | joined$City == "Taipei" | joined$City == "Seoul","North Asia",
                            ifelse(joined$City == "Shanghai","Shanghai",
                                   ifelse(joined$City == "Hong Kong","Hong Kong",
                                          ifelse(joined$City == "Beijing" | joined$City == "Guangzhou" | joined$City == "Shenzhen" | joined$City == "Chengdu" | joined$City == "Tianjin" | joined$City == "Macau","Greater China",
                                                 ifelse(joined$City == "Beijing" | joined$City == "Guangzhou" | joined$City == "Shenzen" | joined$City == "Chengdu" | joined$City == "Tianjin" | joined$City == "Macau","Greater China",
                                                        ifelse(joined$Country == "Australia" | joined$Country == "Singapore" | joined$City == "Jakarta","South APAC",
                                                               ifelse(joined$Country == "India","India","unassinged")))))))
    
  
    
    joined$revenue_per_square_meter = joined$room_revenue / joined$size
    joined$revenue_per_seat = joined$room_revenue / joined$Capacity
    joined$avg_hourly_revenue = joined$room_revenue / joined$hours_booked
    joined$utilization <- joined$hours_booked / as.numeric(input$date_range[2] - input$date_range[1]) * 5.7
    names(joined)[6] <- "Location"
    names(joined)[7] <- "days"
    names(joined)[5] <- "Room"
    occupancy$Country <- NULL
    joined <- inner_join(joined,occupancy,by = "Location")
    
    joined$utilization_level[joined$utilization < 0.06] <- "low"
    joined$utilization_level[joined$utilization > 0.06 & joined$utilization < 0.12] <- "mid"
    joined$utilization_level[joined$utilization > 0.12] <- "high"
    joined$days <- as.numeric(joined$days) / 365
    joined$room_revenue_controlled <- joined$room_revenue / joined$city_factor
    joined$revenue_per_seat_controlled <- joined$revenue_per_seat / joined$city_factor
    joined <- mutate(joined,display = FALSE)
    
    
    if(input$color_differentiation)
    {
      if(input$category_type == "Country")
      {
        for (k in input$countries)
        {
          joined$display[joined$Country == k] <- TRUE
        }
      }
      if(input$category_type == "City")
      {
        for (k in input$cities)
        {
          joined$display[joined$City == k] <- TRUE
        }
      }
      if(input$category_type == "Region")
      {
        for (k in input$regions)
        {
          joined$display[joined$Region == k] <- TRUE
        }
      }
      if(input$category_type == "Location")
      {
        for (k in input$locations)
        {
          joined$display[joined$Region == k] <- TRUE
        }
      }
      if(input$category_type == "Room")
      {
        for (k in input$rooms)
        {
          joined$display[joined$Region == k] <- TRUE
        }
      }
     }
    
    joined <- summarise(group_by_(joined,"Region","display",input$category_type), price_per_meter = mean(price_per_meter),room_revenue = sum(room_revenue),revenue_per_seat = mean(revenue_per_seat), days = mean(days), mean_occupancy = mean(mean_occupancy),mean_utilization = mean(utilization),age_in_years = mean(days),room_revenue_controlled = sum(room_revenue_controlled),revenue_per_seat_controlled = mean(revenue_per_seat_controlled),hours_booked = sum(hours_booked),price_per_seat = mean(price_per_seat),price_per_seat_controlled = mean(price_per_seat_controlled))

    
    
    joined$utilization_level[joined$mean_utilization < summary(joined$mean_utilization)[2]] <- "low"
    joined$utilization_level[joined$mean_utilization >= summary(joined$mean_utilization)[2] & joined$mean_utilization <= summary(joined$mean_utilization)[4]] <- "mid"
    joined$utilization_level[joined$mean_utilization > summary(joined$mean_utilization)[4]] <- "high"
    joined$utilization_level <- as.factor(joined$utilization_level)
    joined
    
  })
  
  output$dot_plot <- renderPlot({
    if(!is.null(room_data()))
      if(input$category_type == "Room")
      {
        
          if(input$point_labels)
          {
            a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization)) + geom_text_repel(aes_string(x=input$x_var,y=input$y_var,label="Room"))
          }
          else
          {
           a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization))
          }
        
          if(!is.null(input$rooms))
          {
              selected <- room_data() %>% filter(display == TRUE)
              not_selected <- room_data() %>% filter(display == FALSE)
              
              if(input$point_labels){a <- ggplot() + geom_point(data = not_selected,aes_string(x = input$x_var,y=input$y_var,size=input$size,alpha=input$opaqeness,shape=input$utilization),color = "grey") + geom_point(data = selected,aes_string(x = input$x_var,y=input$y_var,color = "Region",size=input$size,alpha=input$opaqeness,shape=input$utilization)) + geom_text_repel(data= selected,aes_string(x=input$x_var,y=input$y_var,label="Room",nudge_x = 0.2))}
              else{a <- ggplot() + geom_point(data = not_selected,aes_string(x = input$x_var,y=input$y_var,size=input$size,alpha=input$opaqeness,shape=input$utilization),color = "grey") + geom_point(data = selected,aes_string(x = input$x_var,y=input$y_var,color = "Region",size=input$size,alpha=input$opaqeness,shape=input$utilization))}
          }    
            
        a
      }
    
      else if(input$category_type == "Region")
      {
        if(input$point_labels)
        {
          a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization)) + geom_text_repel(data= room_data(),aes_string(x="price_per_meter",y=input$y_var,label="Region"),nudge_x = 0.2)
        }
        else
        {
          a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization))
        }
        a
      }
      else if(input$category_type == "City")
      {
        if(input$point_labels)
        {
          a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization)) + geom_text_repel(data= room_data(),aes_string(x="price_per_meter",y=input$y_var,label="City"),nudge_x = 0.2)
        }
        else
        {
          a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization))
        }
        
        if(!is.null(input$cities))
        {
          selected <- room_data() %>% filter(display == TRUE)
          not_selected <- room_data() %>% filter(display == FALSE)
          
          if(input$point_labels){a <- ggplot() + geom_point(data = not_selected,aes_string(x = input$x_var,y=input$y_var,size=input$size,alpha=input$opaqeness,shape=input$utilization),color = "grey") + geom_point(data = selected,aes_string(x = input$x_var,y=input$y_var,color = "Region",size=input$size,alpha=input$opaqeness,shape=input$utilization)) + geom_text_repel(data= selected,aes_string(x=input$x_var,y=input$y_var,label="City"),nudge_x = 0.2)}
          else{a <- ggplot() + geom_point(data = not_selected,aes_string(x = input$x_var,y=input$y_var,size=input$size,alpha=input$opaqeness,shape=input$utilization),color = "grey") + geom_point(data = selected,aes_string(x = input$x_var,y=input$y_var,color = "City",size=input$size,alpha=input$opaqeness,shape=input$utilization))}
        }    
        
        a
        
      }
      else if(input$category_type == "Country")
      {
        if(input$point_labels)
        {
          a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization)) + geom_text_repel(data= room_data(),aes_string(x=input$x_var,y=input$y_var,label="Country"),nudge_x = 0.2)
        }
        else
        {
          a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization))
        }
        
        if(!is.null(input$countries))
        {
          selected <- room_data() %>% filter(display == TRUE)
          not_selected <- room_data() %>% filter(display == FALSE)
          
          if(input$point_labels){a <- ggplot() + geom_point(data = not_selected,aes_string(x = input$x_var,y=input$y_var,size=input$size,alpha=input$opaqeness,shape=input$utilization),color = "grey") + geom_point(data = selected,aes_string(x = input$x_var,y=input$y_var,color = "Country",size=input$size,alpha=input$opaqeness,shape=input$utilization)) + geom_text_repel(data= selected,aes_string(x=input$x_var,y=input$y_var,label=Country),nudge_x = 0.2)}
          else{a <- ggplot() + geom_point(data = not_selected,aes_string(x = input$x_var,y=input$y_var,size=input$size,alpha=input$opaqeness,shape=input$utilization),color = "grey") + geom_point(data = selected,aes_string(x = input$x_var,y=input$y_var,color = "Country",size=input$size,alpha=input$opaqeness,shape=input$utilization))}
        }    
        
        a
        
      }
      else if(input$category_type == "Location")
      {
        if(input$point_labels)
        {
          a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization)) + geom_text_repel(data= room_data(),aes_string(x=input$x_var,y=input$y_var,label="Location"),nudge_x = 0.2)
        }
        else
        {
          a <- ggplot(room_data()) + geom_point(aes_string(x=input$x_var,y=input$y_var,color=input$color,size=input$size,alpha=input$opaqeness,shape=input$utilization))
        }
        
        if(!is.null(input$locations))
        {
          selected <- room_data() %>% filter(display == TRUE)
          not_selected <- room_data() %>% filter(display == FALSE)
          
          if(input$point_labels){a <- ggplot() + geom_point(data = not_selected,aes_string(x = input$x_var,y=input$y_var,size=input$size,alpha=input$opaqeness,shape=input$utilization),color = "grey") + geom_point(data = selected,aes_string(x = input$x_var,y=input$y_var,color = "Region",size=input$size,alpha=input$opaqeness,shape=input$utilization)) + geom_text_repel(data= selected,aes_string(x=input$x_var,y=input$y_var,label="Location"),nudge_x = 0.2)}
          else{a <- ggplot() + geom_point(data = not_selected,aes_string(x = input$x_var,y=input$y_var,size=input$size,alpha=input$opaqeness,shape=input$utilization),color = "grey") + geom_point(data = selected,aes_string(x = input$x_var,y=input$y_var,color = "Region",size=input$size,alpha=input$opaqeness,shape=input$utilization))}
        }    
        
        a
      }
    })
  
})



Server.R (app that works fine on Shinyapps.io)

bookings <- NULL
library(dplyr)
library(shiny)
library(tidyverse)
library(reshape2)



options(shiny.maxRequestSize = 9*1024^2)

# Define server logic required to draw a histogram
shinyServer(function(input, output) {
  
  
  ## read in file, filter data, standardize to dollar
  bookings_usdollar <- reactive({
    file1 <- input$file
    if(is.null(file1)){return()}
    bookings <- readxl::read_xlsx(file1$datapath)
    
    bookings <- dplyr::filter(bookings,BookingStatus != "Cancelled")
    bookings <- dplyr::filter(bookings,Date > "2016-10-29" & Date < "2017-05-31")
    bookings <- dplyr::filter(bookings,LocationCode != "CRC")
    
    #change types
    bookings$Date <- as.character(bookings$Date)
    bookings$ResourceCode <- as.character(bookings$ResourceCode)
    bookings$ResourceCode <- as.character(substr(bookings$ResourceCode,1,3))
    #bookings$LocationCode <- as.factor(bookings$ResourceCode)
    bookings$bookingstatus <- as.factor(bookings$BookingStatus)
    bookings$CountryName <- as.factor(bookings$CountryName)
    bookings$CityName <- as.factor(bookings$CityName)
    bookings$LocationName <- as.factor(bookings$LocationName)
    bookings$LocationCode <- as.factor(bookings$LocationCode)
    bookings$EndDate <- as.character(bookings$EndDate)
    bookings$duration <- bookings$TimeEnd - bookings$TimeStart
    bookings$duration <- (as.numeric(bookings$duration)/60)
    bookings$ClientRemarks <- as.character(bookings$ClientRemarks)
    #bookings$BookedFor <- as.character(bookings$BookedFor)
    bookings$ListedPrice <- as.integer(bookings$ListedPrice)
    bookings$ActualPrice <- as.integer(bookings$ActualPrice)
    bookings$seatNum <- as.numeric(bookings$ResourceCapacity)
    bookings$EndDate <- as.Date(bookings$EndDate)
    bookings$Date <- as.Date(bookings$Date)
    bookings$LocationName <- as.factor(bookings$LocationName)
    bookings$Year <- format(bookings$Date,'%Y')
    bookings$Year <- as.numeric(bookings$Year)
    bookings$location_code <- as.character(substr(bookings$ResourceCode,1,3))
    #bookings$TimeStart <- format(bookings$TimeStart,"%H:%M")
    #bookings$TimeEnd <- format(bookings$TimeEnd, "%H:%M")
    bookings$numDays <- bookings$Date - bookings$EndDate
    bookings$hourly_rate <- NULL
    
    ##get rid of tests
    bookings$test_bool <- FALSE
    bookings$test_bool1 <- grepl("test",bookings$BookedFor)
    bookings$test_bool2 <- grepl("Test",bookings$BookedFor)
    bookings$test_bool3 <- grepl("TEST",bookings$BookedFor)
    bookings$test_bool4 <- grepl("test",bookings$ClientRemarks)
    bookings$test_bool5 <- grepl("Test",bookings$ClientRemarks)
    bookings$test_bool6 <- grepl("TEST",bookings$ClientRemarks)
    bookings <- filter(bookings,test_bool1!=TRUE & test_bool2 !=TRUE & test_bool3!=TRUE & test_bool4 !=TRUE & test_bool5!=TRUE & test_bool6 !=TRUE)
    
    
    ######################################
    ########Standardize Currency##########
    ######################################
    australia_2016 <- filter(bookings, CountryName == "Australia" & Year == 2016)
    china_2016 <- filter(bookings, CountryName == "China" & Year == 2016)
    hong_kong_2016 <- filter(bookings, CountryName == "Hong Kong" & Year == 2016)
    india_2016 <- filter(bookings, CountryName == "India" & Year == 2016)
    indonesia_2016 <- filter(bookings, CountryName == "Indonesia" & Year == 2016)
    japan_2016 <- filter(bookings, CountryName == "Japan" & Year == 2016)
    korea_2016 <- filter(bookings, CountryName == "Korea" & Year == 2016)
    macau_2016 <- filter(bookings, CountryName == "Macau" & Year == 2016)
    singapore_2016 <- filter(bookings, CountryName == "Singapore" & Year == 2016)
    taiwan_2016 <- filter(bookings,CountryName == "Taiwan" & Year == 2016)
    australia_2017 <- filter(bookings, CountryName == "Australia" & Year == 2017)
    china_2017 <- filter(bookings, CountryName == "China")
    hong_kong_2017 <- filter(bookings, CountryName == "Hong Kong" & Year == 2017)
    india_2017 <- filter(bookings, CountryName == "India" & Year == 2017)
    indonesia_2017 <- filter(bookings, CountryName == "Indonesia" & Year == 2017)
    japan_2017 <- filter(bookings, CountryName == "Japan" & Year == 2017)
    korea_2017 <- filter(bookings, CountryName == "Korea" & Year == 2017)
    macau_2017 <- filter(bookings, CountryName == "Macau" & Year == 2017)
    singapore_2017 <- filter(bookings, CountryName == "Singapore" & Year == 2017)
    taiwan_2017 <- filter(bookings,CountryName == "Taiwan" & Year == 2017)
    australia_2016$ActualPrice <- australia_2016$ActualPrice / 1.35
    china_2016$ActualPrice <- china_2016$ActualPrice / 6.91
    hong_kong_2016$ActualPrice <- hong_kong_2016$ActualPrice / 7.8
    india_2016$ActualPrice <- india_2016$ActualPrice / 67.2
    indonesia_2016$ActualPrice <- indonesia_2016$ActualPrice / 13281
    singapore_2016$ActualPrice <- singapore_2016$ActualPrice / 1.38
    japan_2016$ActualPrice <- japan_2016$ActualPrice / 109
    korea_2016$ActualPrice <- korea_2016$ActualPrice / 1155
    macau_2016$ActualPrice <- macau_2016$ActualPrice / 7.9
    taiwan_2016$ActualPrice <- taiwan_2016$ActualPrice / 32.2
    australia_2017$ActualPrice <- australia_2017$ActualPrice / 1.31
    china_2017$ActualPrice <- china_2017$ActualPrice / 6.89
    hong_kong_2017$ActualPrice <- hong_kong_2017$ActualPrice / 7.8
    india_2017$ActualPrice <- india_2017$ActualPrice / 67.2
    indonesia_2017$ActualPrice <- indonesia_2017$ActualPrice / 13337.75
    singapore_2017$ActualPrice <- singapore_2017$ActualPrice / 1.4075
    japan_2017$ActualPrice <- japan_2017$ActualPrice / 112
    korea_2017$ActualPrice <- korea_2017$ActualPrice / 1137.125
    macau_2017$ActualPrice <- macau_2017$ActualPrice / 7.9
    taiwan_2017$ActualPrice <- taiwan_2017$ActualPrice / 30.6
    australia_2016$ListedPrice <- australia_2016$ListedPrice / 1.35
    china_2016$ListedPrice <- china_2016$ListedPrice / 6.91
    hong_kong_2016$ListedPrice <- hong_kong_2016$ListedPrice / 7.8
    india_2016$ListedPrice <- india_2016$ListedPrice / 67.2
    indonesia_2016$ListedPrice <- indonesia_2016$ListedPrice / 13281
    singapore_2016$ListedPrice <- singapore_2016$ListedPrice / 1.38
    japan_2016$ListedPrice <- japan_2016$ListedPrice / 109
    korea_2016$ListedPrice <- korea_2016$ListedPrice / 1155
    macau_2016$ListedPrice <- macau_2016$ListedPrice / 7.9
    taiwan_2016$ListedPrice <- taiwan_2016$ListedPrice / 32.2
    australia_2017$ListedPrice <- australia_2017$ListedPrice / 1.31
    china_2017$ListedPrice <- china_2017$ListedPrice / 6.89
    hong_kong_2017$ListedPrice <- hong_kong_2017$ListedPrice / 7.8
    india_2017$ListedPrice <- india_2017$ListedPrice / 67.2
    indonesia_2017$ListedPrice <- indonesia_2017$ListedPrice / 13337.75
    singapore_2017$ListedPrice <- singapore_2017$ListedPrice / 1.4075
    japan_2017$ListedPrice <- japan_2017$ListedPrice / 112
    korea_2017$ListedPrice <- korea_2017$ListedPrice / 1137.125
    macau_2017$ListedPrice <- macau_2017$ListedPrice / 7.9
    taiwan_2017$ListedPrice <- taiwan_2017$ListedPrice / 30.6
    bookings_usd <- rbind(australia_2016,china_2016,hong_kong_2016,india_2016,indonesia_2016,singapore_2016,japan_2016,korea_2016,macau_2016,taiwan_2016,australia_2017,china_2017,hong_kong_2017,india_2017,indonesia_2017,singapore_2017,japan_2017,korea_2017,macau_2017,taiwan_2017)
    
    ##various filters
    bookings_usd$meeting_revenue <- bookings_usd$ActualPrice * bookings_usd$duration
    bookings_usd$price_per_seat <- bookings_usd$ListedPrice/bookings_usd$seatNum
    bookings_usd$Discount <- bookings_usd$ListedPrice - bookings_usd$ActualPrice
    bookings_usd <- filter(bookings_usd,duration>0)
    bookings_usd <- filter(bookings_usd,meeting_revenue<1000000)
    bookings_usd$RoomNum <- as.factor(bookings_usd$ResourceCapacity)
    bookings_usd <- bookings_usd[!is.na(bookings_usd$ActualPrice),]
    bookings_usd <- bookings_usd[!is.na(bookings_usd$price_per_seat),]
    bookings_usd <- dplyr::filter(bookings_usd,ListedPrice < 600)
    bookings_usd[!is.na(bookings_usd$ListedPrice),]
    
  })
  
  ########Summarized data
  categorical_data <- reactive({
    if(is.null(bookings_usdollar())){return()}
    
    if(input$category_type == "Display by City")
    {
      if(is.null(input$cities)){return()}
      
      this_data <- tibble()
      
      for (k in input$cities)
      {
        current <- bookings_usdollar() %>% filter(CityName==k)
        this_data <- rbind(this_data,current)
      }
      
      if(input$room_filter)
      {   
          this_data <- filter(this_data,RoomNum==input$seatNum)
      }    
      current <- summarize(group_by(this_data, CityName), avg_hourly_price = mean(ActualPrice),avg_hourly_listed_price=mean(ListedPrice),total_app_revenue = sum(ActualPrice),avg_meeting_revenue = mean(meeting_revenue),avg_duration=mean(duration),avg_capacity = mean(ResourceCapacity))
    }
    
    else if(input$category_type == "Display by Country")
    {
      if(is.null(input$countries)){return()}
      
      this_data <- tibble()
      
      for (k in input$countries)
      {
        current <- bookings_usdollar() %>% filter(CountryName==k)
        this_data <- rbind(this_data,current)
      }
      
        if(input$room_filter)
        {   
          this_data <- filter(this_data,RoomNum == input$seatNum)
        }
          
      current <- summarize(group_by(this_data, CountryName), avg_hourly_price = mean(ActualPrice),avg_hourly_listed_price=mean(ListedPrice),total_app_revenue = sum(ActualPrice),avg_meeting_revenue = mean(meeting_revenue),avg_duration=mean(duration),avg_capacity = mean(ResourceCapacity))
        
      }
    else if(input$category_type == "Display by Centre")
    {
      if(is.null(input$centres)){return()}
      
      this_data <- tibble()
      
      for (k in input$centres)
      {
        current <- bookings_usdollar() %>% filter(location_code==k)
        this_data <- rbind(this_data,current)
      }
      
      if(input$room_filter)
      {   
        this_data <- filter(this_data,RoomNum == input$seatNum)
      }  
        current <- summarize(group_by(this_data, LocationName), avg_hourly_price = mean(ActualPrice),avg_hourly_listed_price=mean(ListedPrice),total_app_revenue = sum(meeting_revenue),avg_meeting_revenue = mean(ActualPrice),avg_duration=mean(duration),avg_capacity = mean(ResourceCapacity))
      
    }
    current$avg_discount = current$avg_hourly_listed_price - current$avg_hourly_price
    current$avg_per_seat = current$avg_hourly_listed_price / current$avg_capacity
    current
    
  })
  
  seat_revenue <- reactive({
    if(input$category_type == "Display by City")
    {
      if(is.null(input$cities)){return()}
      
      this_data <- tibble()
      
      for (k in input$cities)
      {
        current <- bookings_usdollar() %>% filter(CityName==k)
        this_data <- rbind(this_data,current)
      }
      
      if(input$room_filter)
      {   
        this_data <- filter(this_data,RoomNum == input$seatNum)
      }
      
      seat_summary <- summarize(group_by(this_data, CityName,seatNum),avg_perSeat = mean(price_per_seat),revenue = sum(ActualPrice))
      seat_summary$seatNum <- as.factor(seat_summary$seatNum)
    }
    
    else if(input$category_type == "Display by Country")
    {
      if(is.null(input$countries)){return()}
      
      this_data <- tibble()
      
      for (k in input$countries)
      {
        current <- bookings_usdollar() %>% filter(CountryName==k)
        this_data <- rbind(this_data,current)
      }
      
      if(input$room_filter)
      {   
        this_data <- filter(this_data,RoomNum == input$seatNum)
      }
      
      seat_summary <- summarize(group_by(this_data, CountryName,seatNum),avg_perSeat = mean(price_per_seat),revenue = sum(ActualPrice))
      seat_summary$seatNum <- as.factor(seat_summary$seatNum)
    }
      
    else if(input$category_type == "Display by Centre")
    {
      if(is.null(input$centres)){return()}
      
      this_data <- tibble()
      
      for (k in input$centres)
      {
        current <- bookings_usdollar() %>% filter(location_code==k)
        this_data <- rbind(this_data,current)
      }
      
      if(input$room_filter)
      {   
        this_data <- filter(this_data,RoomNum == input$seatNum)
      }
      
      seat_summary <- summarize(group_by(this_data, LocationName,seatNum),avg_perSeat = mean(price_per_seat),revenue = sum(ActualPrice))
      seat_summary$seatNum <- as.factor(seat_summary$seatNum)
    }
    seat_summary
  })
  
  hr_price_summary <- reactive({
    if(input$category_type == "Display by City")
    {
      this_data <- tibble()
      
      for (k in input$cities)
      {
        current <- bookings_usdollar() %>% filter(CityName==k)
        this_data <- rbind(this_data,current)
      }
      
      if(input$room_filter)
      {   
        this_data <- filter(this_data,RoomNum == input$seatNum)
      }
      
      if(is.null(input$cities))
      {
         this_data <- bookings_usdollar()
      }
    }
    
    else if(input$category_type == "Display by Country")
    {
      this_data <- tibble()
      
      for (k in input$countries)
      {
        current <- bookings_usdollar() %>% filter(CountryName==k)
        this_data <- rbind(this_data,current)
      }
      
      if(input$room_filter)
      {   
        this_data <- filter(this_data,RoomNum == input$seatNum)
      }
      
      if(is.null(input$countries))
      {
        this_data <- bookings_usdollar()
      }
    }
        
    else if(input$category_type == "Display by Centre")
    {
      this_data <- tibble()
      
      for (k in input$centres)
      {
        current <- bookings_usdollar() %>% filter(LocationCode==k)
        this_data <- rbind(this_data,current)
      }
      
      if(input$room_filter)
      {   
        this_data <- filter(this_data,RoomNum == input$seatNum)
      }
      
      if(is.null(input$centres))
      {
        this_data <- bookings_usdollar()
      }
    }
    
    
    price_v_hrs <- summarize(group_by(this_data,LocationCode), avg_price = mean(as.numeric(levels(as.factor(ListedPrice)))),total_hrs = sum(duration),seats_sold = sum(ResourceCapacity),avg_capacity = mean(as.numeric(levels(as.factor(ResourceCapacity)))),total_app_revenue = sum(ActualPrice))
    price_v_hrs$avg_per_seat <- (price_v_hrs$avg_price / price_v_hrs$avg_capacity)
    price_v_hrs
  })
  
  
  

  var_index <- reactive({
  if(input$category_type == "Display by City"){category <- 72}
  if(input$category_type == "Display by Country"){category <- 77}
  if(input$category_type == "Display by Centre"){category <- 62}
    category
  })
  
  
  
  
  ############# Not summarized
  aggregate_data <- reactive({
    if(is.null(bookings_usdollar())){return()}
    
    if(input$category_type == "Display by City")
    {
      this_data <- tibble()
      for (k in input$cities)
      {
        current <- bookings_usdollar() %>% filter(CityName==k)
        this_data <- rbind(this_data,current)
      }
    }
    
    else if(input$category_type == "Display by Country")
    {
      this_data <- tibble()
      for (k in input$countries)
      {
        current <- bookings_usdollar() %>% filter(CountryName==k)
        this_data <- rbind(this_data,current)
      }
    }
    
    else if(input$category_type == "Display by Centre")
    {
      this_data <- tibble()
      for (k in input$centres)
      {
        current <- bookings_usdollar() %>% filter(location_code==k)
        this_data <- rbind(this_data,current)
      }
      
    }
    
    if(input$room_filter)
    {   
      this_data <- filter(this_data,RoomNum == input$seatNum)
    }
    this_data
  })
  
  
  output$scatterplot <- renderPlot ({
    if(is.null(bookings_usdollar())){return()}
    ggplot(hr_price_summary(),aes(x=total_hrs,y=avg_per_seat)) + geom_point() + geom_smooth(aes(x=total_hrs,y=avg_per_seat),inherit.aes = FALSE,method = 'lm',se=FALSE) + geom_text(aes(label= LocationCode),nudge_y = 3) + labs(title = "Average Price Per Seat vs Total Hours Booked",x = "Total Hours Booked",y = "Average Price Per Seat")
  })
  
  output$second_scatterplot <- renderPlot({
    if(is.null(bookings_usdollar())){return}
    ggplot(hr_price_summary(),aes(x=seats_sold,y=avg_per_seat)) + geom_point() + geom_smooth(aes(x=seats_sold,y=avg_per_seat),inherit.aes = FALSE,method = 'lm',se=FALSE) + geom_text(aes(label= LocationCode),nudge_y = 3) + labs(title = "Average Price Per Seat vs Total Seats Booked", x = "Total Number of Seats Booked",y = "Average Price Per Seat")
  })
  
 # output$myTable <- renderTable({
   # seat_revenue()
  #})
 
  output$discount_plot <- renderPlot({
    if(is.null(categorical_data())){return()}
    droppedVars <-names(categorical_data()) %in% c("total_app_revenue","avg_meeting_revenue","avg_meeting_revenue","avg_duration","avg_hourly_listed_price","mean_hourly_pp_price","avg_capacity")
    discounts <- categorical_data()[!droppedVars]
    discounts <- discounts[c(1,3,2)]
    names(discounts)[1] <- "location"
    data_melt <- melt(discounts)
    hrly_price <- filter(data_melt, variable == "avg_hourly_price")
    
    x_list <- data_melt$location[order(hrly_price$value)]
    
    a <- ggplot(data_melt, aes(x = location, y= value, fill = variable), xlab="Categories") + geom_bar(stat="identity", width=0.6, position = "stack") + scale_y_continuous(name="Dollars") + labs(title = "Average Hourly Discount vs Average Hourly Revenue") + theme(axis.text.x=element_text(angle=90, hjust=1))
    a + scale_x_discrete(limits = x_list)
  })
  
  output$date_plot <- renderPlot({
   if(is.null(aggregate_data())){return()}
    if(input$category_type == "Display by Country"){a <- ggplot(aggregate_data(),aes(x=Date,color=CountryName,fill=CountryName)) + geom_density(alpha= 0) + scale_x_date(date_breaks = "1 month") + labs(title = "This is a density or frequency plot of booking dates \n The best interpretation of this is to view it as a probability distribution. \n For Example: click Divide by City and then select Hong Kong. \n Then, open the app data spreadsheet in Excel, \n filter out all the bookings that are not made in Hong Kong \n close your eyes and scroll down the spreadsheet, stopping at a random booking record \n The probability of landing on a booking in mid march (the peak) is a \n little over 1% (0.01 on the Y-Axis). The probability of landing \n on a booking on new years day is a quarter of one percent \n CAUTION: The reason why there are so few bookings toward the far left \n hand of the graph is not because this time of year is unpopular, \n but likely because it took a little  while for clients to start \n using the app. This plot starts on November 1st, 2016 which was the day after \n the app went live.")} 
    if(input$category_type == "Display by City"){a <- ggplot(aggregate_data(),aes(x=Date,color=CityName,fill=CityName)) + geom_density(alpha= 0) + scale_x_date(date_breaks = "1 month") + labs(title = "This is a density or frequency plot of booking dates \n The best interpretation of this is to view it as a probability distribution. \n For Example: click Divide by City and then select Hong Kong. \n Then, open the app data spreadsheet in Excel, \n filter out all the bookings that are not made in Hong Kong \n close your eyes and scroll down the spreadsheet, stopping at a random booking record \n The probability of landing on a booking in mid march (the peak) is a \n little over 1% (0.01 on the Y-Axis). The probability of landing \n on a booking on new years day is a quarter of one percent \n CAUTION: The reason why there are so few bookings toward the far left \n hand of the graph is not because this time of year is unpopular, \n but likely because it took a little  while for clients to start \n using the app. This plot starts on November 1st, 2016 which was the day after \n the app went live.") }
    if(input$category_type == "Display by Centre"){a <- ggplot(aggregate_data(),aes(x=Date,color=LocationName,fill=LocationName)) + geom_density(alpha= 0) + scale_x_date(date_breaks = "1 month")+ labs(title = "This is a density or frequency plot of booking dates \n The best interpretation of this is to view it as a probability distribution. \n For Example: click Divide by City and then select Hong Kong. \n Then, open the app data spreadsheet in Excel, \n filter out all the bookings that are not made in Hong Kong \n close your eyes and scroll down the spreadsheet, stopping at a random booking record \n The probability of landing on a booking in mid march (the peak) is a \n little over 1% (0.01 on the Y-Axis). The probability of landing \n on a booking on new years day is a quarter of one percent \n CAUTION: The reason why there are so few bookings toward the far left \n hand of the graph is not because this time of year is unpopular, \n but likely because it took a little  while for clients to start \n using the app. This plot starts on November 1st, 2016 which was the day after \n the app went live.")}
    a
  },height = 600)
  
  output$time_plot <- renderPlot({
    if(is.null(aggregate_data())){return()}
    if(input$category_type == "Display by Country"){b <- ggplot(aggregate_data(),aes(x=TimeStart,color=CountryName,fill=CountryName)) + geom_density(alpha= 0) + scale_x_datetime(breaks = "1 hour") + labs(title = "This plot has exactly the same interpretation as the date plot above \n but it shows the density of meeting start times")} #+ scale_x_datetime(limits =lims, breaks=date_breaks("1 hour"), labels=date_format("%H:%M"))+ theme(axis.text.x=element_text(angle=90))}
    if(input$category_type == "Display by City"){b <- ggplot(aggregate_data(),aes(x=TimeStart,color=CityName,fill=CityName)) + geom_density(alpha= 0) + labs(title = "This plot has exactly the same interpretation as the date plot above \n but it shows the density of meeting start times")} #+ scale_x_datetime(limits =lims, breaks=date_breaks("1 hour"), labels=date_format("%H:%M"))+ theme(axis.text.x=element_text(angle=90))}
    if(input$category_type == "Display by Centre"){b <- ggplot(aggregate_data(),aes(x=TimeStart,color=LocationName,fill=LocationName)) + geom_density(alpha= 0) + labs(title = "This plot has exactly the same interpretation as the date plot above \n but it shows the density of meeting start times")} #+ scale_x_datetime(limits =lims, breaks=date_breaks("4 hour"), labels=date_format("%H:%M")) + theme(axis.text.x=element_text(angle=90))}
    b
    
  })
  
  output$revenue_plot <- renderPlot({
    if(is.null(seat_revenue())){return()}
    {
      
      if(input$category_type == "Display by Country")
      {
        f <- ggplot(seat_revenue(), aes(x=CountryName,y=revenue,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Total Revenue From Each Type of Room", y= "Dollars")
      }
      if(input$category_type == "Display by City")
      {
        f <- ggplot(seat_revenue(), aes(x=CityName,y=revenue,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Total Revenue From Each Type of Room", y= "Dollars")
      }
      if(input$category_type == "Display by Centre")
      {
        f <- ggplot(seat_revenue(), aes(x=LocationName,y=revenue,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Total Revenue From Each Type of Room", y= "Dollars")
      }
      f
    }
    
  })
  booking_dates_reactive <- reactive({
    if(is.null(bookings_usdollar())){return()}
    bookings_small <- bookings_usdollar()["Date"]
    bookings_small$day <- weekdays(bookings_small$Date)
    booking_dates <- table(bookings_small$Date)
    booking_dates <- as.data.frame(booking_dates)
    names(booking_dates)[1] <- "Date"
    names(booking_dates)[2] <- "BookingCount"
    booking_dates$Date <- as.Date(booking_dates$Date)
    booking_dates$WeekDay <- weekdays(booking_dates$Date)
    booking_dates$WeekDay <- as.factor(booking_dates$WeekDay)
    booking_dates
    
  })
  
  
  
  output$per_seat_plot <- renderPlot({
    if(is.null(seat_revenue())){return()}
    {
      
      if(input$category_type == "Display by Country")
      {
        f <- ggplot(seat_revenue(), aes(x=CountryName,y=avg_perSeat,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Average Hourly Price Per Seat", y= "Dollars")
      }
      if(input$category_type == "Display by City")
      {
        f <- ggplot(seat_revenue(), aes(x=CityName,y=avg_perSeat,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Average Hourly Price Per Seat", y= "Dollars")
      }
      if(input$category_type == "Display by Centre")
      {
        f <- ggplot(seat_revenue(), aes(x=LocationName,y=avg_perSeat,fill=seatNum)) + geom_bar(position="dodge", stat="identity") + labs(title = "Average Hourly Price Per Seat", y= "Dollars")
      }
      f
    }
    
  })
  
  
  
  
  
  
  
  
  output$roomNumber_plot <- renderPlot({
    if(is.null(aggregate_data())){return()}
    
    if(input$category_type == "Display by Country")
    {
    keepvars <- c("CountryName","RoomNum")
    room_nums <- aggregate_data()[keepvars]
    names(room_nums)[1] <- "location"
    }
    else if(input$category_type == "Display by City")
    {
    keepvars <- c("CityName","RoomNum")
    room_nums <- aggregate_data()[keepvars]
    names(room_nums)[1] <- "location"
    }
    else if(input$category_type == "Display by Centre")
    {
    keepvars <- c("location_code","RoomNum")
    room_nums <- aggregate_data()[keepvars]
    names(room_nums)[1] <- "location"
    }
    
    
    
    if(input$category_type == "Display by Country")
    {
    x_list <- names(sort(table(room_nums$location)))
    x_list <- intersect(x_list,input$countries)
    c <- ggplot(room_nums, aes(x=location,fill=RoomNum)) + geom_bar(stat="count") + scale_x_discrete(limits = x_list) + labs(title = "Total Number of Meeting Room Bookings",y= "Total Number of Meeting Room Bookings per Country")
    }
    else if(input$category_type == "Display by City")
    {
    x_list <- names(sort(table(room_nums$location)))
    x_list <- intersect(x_list,input$cities)
    c <- ggplot(room_nums, aes(x=location,fill=RoomNum)) + geom_bar(stat="count") + scale_x_discrete(limits = x_list) + scale_x_discrete(limits = x_list) + labs(title = "Total Number of Meeting Room Bookings",y= "Total Number of Meeting Room Bookings per City")
    }
    else if(input$category_type == "Display by Centre")
    {
    x_list <- names(sort(table(room_nums$location)))
    x_list <- intersect(x_list,input$centres)
    c <- ggplot(room_nums, aes(x=location,fill=RoomNum)) + geom_bar(stat="count") + scale_x_discrete(limits = x_list) + labs(title = "Total Number of Meeting Room Bookings",y= "Total Number of Meeting Room Bookings per Centre")
    }
    c
    
    })
  output$day_plot <- renderPlot({
    if(is.null(booking_dates_reactive())){return()}
    daily_data <- booking_dates_reactive() %>% filter(WeekDay == input$weekday)
    g <- ggplot(daily_data) + geom_bar(aes(x=Date,y=BookingCount,color=WeekDay),stat="identity") + scale_y_continuous(limits=(c(0,200)))
    g
    
  })
  
  
})



There are very few substantive differences between these two apps, so I can't tell why one is working an another one isn't. Any help would be much appreciated!














Bookings_4.xlsx

Joshua Spiewak

unread,
Jul 21, 2017, 8:59:19 AM7/21/17
to shinyapps.io Users
rJava is used by xlsx.

There is an issue with rJava & R 3.4.0 for which we are looking for a permanent solution.

In the meantime, there are two ways of working around the problem: 1) downgrade R to 3.3.3 or 2) add options(java.parameters = "-Xss2048k") before your library calls

Hope that helps, sorry for the trouble
...

Lotte Kortland

unread,
Nov 21, 2017, 4:54:02 AM11/21/17
to shinyapps.io Users
Thansk Joshua, I deleted the loading of xlsx and my app started running again. 

Op vrijdag 21 juli 2017 14:59:19 UTC+2 schreef Joshua Spiewak:

Joshua Spiewak

unread,
Nov 21, 2017, 8:59:04 AM11/21/17
to shinyapps.io Users
The latest version of rJava contains a permanent fix for this issue as well.
...
Reply all
Reply to author
Forward
0 new messages