rshinygoogle-sheets-apir-leaflet

Error in deploying shinyapp using leaflet and googlesheets API


I am working on a shinyapp that works locally, but throws an error everytime I try to publish it on shinyapps.io.

I have published apps using leaflet and they work, and I have also used googlesheets in other apps and that package works fine too. But when I use them altogether the app returns Error : there is no package called ‘leaflet’. Which is strange, because in this example app it does find the package.

leaflet working:

library(shiny)
library(leaflet)

# UI 
ui <-(fluidPage("Example", leafletOutput("map")))

# Server 
server = (function(input, output) {
  output$map   <- renderLeaflet({
      leaflet()    %>% 
        addProviderTiles("CartoDB.Positron")   %>% 
        setView(-58.43152, -34.6052, zoom=11 )    
  })
})

shinyApp(ui = ui, server = server)

leaflet not working:

library(shiny)
library(leaflet)
library(googlesheets)
library(sp)
library(rgdal)
library(DT)

options("googlesheets.httr_oauth_cache" = "gs_auth")
gs_auth()
rdv <- gs_url("https://docs.google.com/spreadsheets/d/1eWxmy7kSjWVfloJiS4ycjn4YKx2OybIzWogX7ga4fUQ/edit?usp=sharing", lookup = NULL, visibility = NULL, verbose = TRUE)

shape  <- readRDS("shape_ok.rds")
bounds <- bbox(shape)

sheet <- gs_read(rdv, ws = 3)


# UI
ui <-(fluidPage("Example", 
                  leafletOutput("map"),
                  dataTableOutput("table")
               )
)

# Server
server = (function(input, output) {

  output$map   <- renderLeaflet({
      leaflet(shape)    %>% 
        addProviderTiles("CartoDB.Positron")    %>% 
        setView(-58.43152, -34.6052, zoom=11 )  %>%
        addPolygons(stroke = T, fillOpacity = 0.65, smoothFactor = 0.5)
  })

  output$table <- renderDataTable({ as.data.frame(sheet) })

})

# Run the application 
shinyApp(ui = ui, server = server)

I have also deployed apps using googlesheets only and they work. So I have no clue of what's going on when I use both packages and get the leaflet error.


Solution

  • I downloaded an Argentinian RDS file and got it to work locally without changes (albiet with warnings). I also sucessfully published it to shinyapps.io at this URL:https://mikewise2718.shinyapps.io/Argentina/

    I used RStudio version: 0.99.903

    So it might be some kind of version problem, here is my sessionInfo():

    R version 3.3.2 (2016-10-31)
    Platform: x86_64-w64-mingw32/x64 (64-bit)
    Running under: Windows >= 8 x64 (build 9200)
    
    locale:
    [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
    [5] LC_TIME=English_United States.1252    
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     
    
    other attached packages:
    [1] DT_0.2             rgdal_1.1-10       sp_1.2-3           googlesheets_0.2.1 leaflet_1.0.1      shiny_0.14.2      
    
    loaded via a namespace (and not attached):
     [1] Rcpp_0.12.7      xml2_1.0.0       magrittr_1.5     xtable_1.8-2     lattice_0.20-34  R6_2.2.0         stringr_1.1.0    httr_1.2.1       dplyr_0.5.0     
    [10] tools_3.3.2      grid_3.3.2       DBI_0.5-1        htmltools_0.3.5  yaml_2.1.14      lazyeval_0.2.0   openssl_0.9.5    assertthat_0.1   digest_0.6.10   
    [19] tibble_1.2       RJSONIO_1.3-0    readr_1.0.0      purrr_0.2.2      bitops_1.0-6     htmlwidgets_0.8  RCurl_1.95-4.8   rsconnect_0.4.3  curl_2.2        
    [28] mime_0.5         stringi_1.1.2    cellranger_1.1.0 jsonlite_1.1     httpuv_1.3.3