Closed BFroebRPG closed 1 year ago
library(shiny)
library(tmap); tmap_mode('view')
library(sf)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
tmapOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
counties <- read_sf('https://gist.githubusercontent.com/sdwfrost/d1c73f91dd9d175998ed166eb216994a/raw/e89c35f308cee7e2e5a784e1d3afc5d449e9e4bb/counties.geojson')
output$distPlot <- renderTmap({
# generate bins based on input$bins from ui.R
tm_shape(counties) + tm_polygons()
})
}
# Run the application
shinyApp(ui = ui, server = server)
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
time zone: America/New_York
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] sf_1.0-14 tmap_3.3-4 shiny_1.7.5
loaded via a namespace (and not attached):
[1] bslib_0.5.1 raster_3.6-23 htmlwidgets_1.6.2 lattice_0.21-8
[5] leaflet.providers_1.13.0 vctrs_0.6.3 tools_4.3.1 crosstalk_1.2.0
[9] generics_0.1.3 parallel_4.3.1 tibble_3.2.1 proxy_0.4-27
[13] fansi_1.0.4 pkgconfig_2.0.3 KernSmooth_2.23-21 RColorBrewer_1.1-3
[17] leaflet_2.2.0 lifecycle_1.0.3 compiler_4.3.1 terra_1.7-46
[21] codetools_0.2-19 leafsync_0.1.0 httpuv_1.6.11 stars_0.6-3
[25] htmltools_0.5.6 class_7.3-22 sass_0.4.7 pillar_1.9.0
[29] later_1.3.1 jquerylib_0.1.4 ellipsis_0.3.2 rsconnect_1.1.0
[33] classInt_0.4-9 cachem_1.0.8 lwgeom_0.2-13 wk_0.8.0
[37] abind_1.4-5 mime_0.12 tidyselect_1.2.0 digest_0.6.33
[41] dplyr_1.1.2 fastmap_1.1.1 grid_4.3.1 cli_3.6.1
[45] magrittr_2.0.3 base64enc_0.1-3 dichromat_2.0-0.1 XML_3.99-0.14
[49] utf8_1.2.3 leafem_0.2.0 e1071_1.7-13 withr_2.5.0
[53] promises_1.2.1 sp_2.0-0 png_0.1-8 memoise_2.0.1
[57] tmaptools_3.1-1 viridisLite_0.4.2 s2_1.1.4 rlang_1.1.1
[61] Rcpp_1.0.11 xtable_1.8-4 glue_1.6.2 DBI_1.1.3
[65] rstudioapi_0.15.0 jsonlite_1.8.7 R6_2.5.1 units_0.8-3
Does a shiny app with leaflet or mapview (instead of tmap) work?
yes, wrapping the tmap object in tmap_leaflet
and then switching to renderLeaflet
and leafletOutput
works, but none of the base tmap functions
So it's just an issue with shinyapps.io, right? Locally, it works.
Could you also test mapview? (e.g. renderMapview
etc). Mapview should work the same way as tmap.
No it happens on local apps as well
I do not use mapview very often (I didn't even have the package installed) so I could be implementing it incorrectly, but
library(shiny)
library(tmap); tmap_mode('view')
library(sf)
library(mapview)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
mapviewOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
counties <- read_sf('https://gist.githubusercontent.com/sdwfrost/d1c73f91dd9d175998ed166eb216994a/raw/e89c35f308cee7e2e5a784e1d3afc5d449e9e4bb/counties.geojson')
output$distPlot <- renderMapview({
# generate bins based on input$bins from ui.R
mapview(counties)
})
}
# Run the application
shinyApp(ui = ui, server = server)
generates the following error
Warning: Error in exprToQuo: Don't know how to convert 'leaflet' to a function; a quosure or quoted expression was expected
44: stop
43: exprToQuo
42: exprToFunction
41: shiny::installExprFunction
40: htmlwidgets::shinyRenderWidget
39: renderMapview
38: server [C:\Users\BrianFroeb\Documents\shinyTesting/app.R#43]
1: shiny::runApp
Error in exprToQuo(expr, env, quoted = TRUE) :
Don't know how to convert 'leaflet' to a function; a quosure or quoted expression was expected
To pitch in here, I don't think the mapview shiny functions work at all... I always recommend using the @map
slot with the standard leaflet shiny functions. In short, mapview won't be any help in tracking down the issue here.
Thx @tim-salabim same approach in tmap.
The example worked for me, until I updated shiny from 1.7.4 to 1.7.5 and leaflet from 2.1.2 to 2.2.0....
Working. Please test @BFroebRPG
It appears to be! Thanks so much!
I recently updated packages of my R enviornment to sort out a deployment issue with shinyapps.io and have now encountered an issue where none of the tmaps in my application are being rendered. I created a simpler application to test and have found the same issue.