if (interactive()) {
library(surveydown)
library(leaflet)
server <- function(input, output, session) {
# Create map output
output$usa_map <- renderLeaflet({
leaflet() |>
addTiles() |>
setView(lng = -98.5795, lat = 39.8283, zoom = 4)
})
# Reactive value for selected location
selected_location <- reactiveVal(NULL)
# Click observer
observeEvent(input$usa_map_click, {
click <- input$usa_map_click
if (!is.null(click)) {
selected_location(
sprintf("Lat: %0.2f, Lng: %0.2f", click$lat, click$lng)
)
}
})
# Create the custom question
sd_question_custom(
id = "location",
label = "Click on your location:",
output = leafletOutput("usa_map", height = "400px"),
value = selected_location
)
sd_server()
}
shinyApp(ui = sd_ui(), server = server)
}
Run the code above in your browser using DataLab