I am a beginner in R mapping and I am trying to build an Shiny app to visualise student satisfaction for all the universities in the UK (values range from 72-97).
Through leaflet I have mapped the university locations with markers and added popups to see the student satisfaction score.
Now I would like to create a reactive slider which allows to choose a satisfaction value resulting in only the universities that scored at least the score selected are displayed on the map using leafletProxy().
Below you can see my code so far with a screenshot of how it looks. As of now, the slider and the map are displayed and the app runs, but it is not reactive.
Any tips on how to continue?
ui <- bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
leafletOutput("uniSmap", width = "100%", height = "100%"),
absolutePanel(top = 50, right = 50,
sliderInput("range", "Satisfaction Score", min(my_shiny_Data$`Satisfaction (%) 2016 Registered`), max(my_shiny_Data$`Satisfaction (%) 2016 Registered`),
value = range(my_shiny_Data$`Satisfaction (%) 2016 Registered`), step = 1 )
)
)
server <- function(input, output, session) {
# Reactive expression for the data subsetted to what the user selected
reactiveData <- reactive({
my_shiny_Data[my_shiny_Data$`Satisfaction (%) 2016 Registered` >= input$range[1] & my_shiny_Data$`Satisfaction (%) 2016 Registered` <= input$range[2],]
})
output$uniSmap <- renderLeaflet({
# Use leaflet() here for static map
uniSmap = leaflet() %>%
addTiles() %>%
setView(lng = -2.2, lat = 54.5, zoom = 6) #%>%
})
# Incremental changes to the map performed in an observer.
observe({
leafletProxy("uniSmap", data = reactiveData()) %>%
clearShapes() %>% clearPopups() %>% clearMarkers() %>%
addMarkers(lng = my_shiny_Data$Longitude,
lat = my_shiny_Data$Latitude,
popup = paste(my_shiny_Data$Institution, "<br>",
"Overall Satisfaction:", my_shiny_Data$`Satisfaction (%) 2016 Registered`, "<br>"))
})
}
shinyApp(ui = ui, server = server)
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/810f6df5-a584-4446-9f21-68f65eb8de06%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/810f6df5-a584-4446-9f21-68f65eb8de06%40googlegroups.com.