I'd like to construct a shiny app with leaflet displaying the locations of Ukraininan power plants. In the UI users shall have the option to select the plants shown based on the fuel type (e.g. nuclear, coal, hydro, wind, solar, gas). The data are from the global power plant database:
The sidebar panel, as well as the leaflet map are displayed correctly, yet the app is not reactive, i.e. the markers do not change based on the inputs in the sidebar panels, but are statically shown all at once, reagardless of the UI input (see screenshot below).
There is probbaly some mistake in the server function of my code. I am new to shiny programming, so it can be a very basic mistake.
library(shiny)
library(dplyr)
library(leaflet)
UkraineLatitude<-48.383022
UkraineLongitude<-31.1828699
DS_Power_Plants<-read.csv("xxx")
Power_Plants_UKR<-filter(DS_Power_Plants, country=="UKR")
ui <- fluidPage(
titlePanel("Power Plant map of Ukraine"),
sidebarLayout(
sidebarPanel(
selectInput("PlantType",
"Power Plants by fuel type",
choices = Power_Plants_UKR$primary_fuel,
selected=NULL,
multiple=TRUE),
),
mainPanel(leafletOutput(outputId = "Plantmap"))
)
)
server <- function(input, output) {
reactive({
Power_Plants_UKR%>%filter(Power_Plants_UKR$primary_fuel,input$PlantType)
})
output$Plantmap<-renderLeaflet({
leaflet(Power_Plants_UKR)%>%
addTiles()%>%addMarkers()
})
}
shinyApp(ui = ui, server = server)
Somehow there seems to be a problem with linking the reactive function and the renderLeaflet function.