Alright, so I am stumped. See below for a reproducible R/Shiny/Leaflet example.
If I try to embed a numeric input into a leaflet map, as illustrated below, I am unable to call the value specified in the numeric input. What is the correct way to get a numeric input to work inside a leaflet map in Shiny? I have tried a few things - a. what you see below, b. creating a ui object, c. reactive functions and d. various combinations thereof - but no bananas.
Would really appreciate the help.
library(shiny)
library(leaflet)
library(dplyr)
content <- paste(sep = "<br/>",
"<b>Change number below:</b>",
numericInput("numeroUno", label = NULL, value = 1)
)
ui <- fluidPage(
"This is a map",
leafletOutput("myMap"),
numericInput('numeroDos', label = NULL, value = 5),
textOutput("mapPopupLink"))
server <- function(input, output, session) {
output$myMap <- renderLeaflet({
leaflet() %>%
setView(lng = 25.0343, lat = 77.3963, zoom = 5) %>%
addPopups(-122.327298, 47.597131, content, options = popupOptions(closeButton = FALSE)) %>%
addTiles() %>%
addProviderTiles(providers$OpenTopoMap)
})
output$mapPopupLink <- renderText({
paste("The ui-based widget prints: ", input$numeroDos, ". But the server-based widget does not: ", input$numeroUno)
})
}
shinyApp(ui, server)
Let me know if you have any questions...thanks!