Skip to content

Commit

Permalink
Attempt to resolve static element error
Browse files Browse the repository at this point in the history
  • Loading branch information
akutsupis committed Dec 5, 2023
1 parent 9150d0d commit cb9a91c
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions EU_Transportation_Modes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ nuts_sf_filtered$CountryCode <- substr(nuts_sf_filtered$NUTS_ID, 1, 2)
# Merge on country code keys
merged_data <- merge(nuts_sf_filtered, data, by.x = "CountryCode", by.y = "geo", all.x = TRUE)
```

```{r}
Expand All @@ -74,27 +73,28 @@ server <- function(input, output, session) {
req(input$year_slider)
na.omit(merged_data[merged_data$TIME_PERIOD == input$year_slider, ])
})
colorpal <- reactive({
colorNumeric("Blues", merged_data$OBS_VALUE)
})
# Create leaflet map with static elements
output$map <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolygons(data = filtered_data(),
fillColor = colorpal()(filtered_data()$OBS_VALUE),
fillOpacity = 0.6,
weight = 2,
color = "white",
popup = ~paste("Country: ", filtered_data()$CountryCode, "<br>",
"Freight Mode: ", filtered_data()$tra_mode, "<br>",
"Percent: ", filtered_data()$OBS_VALUE)
)
})
# Create leaflet map with static elements
output$map <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolygons(data = filtered_data(),
fillColor = colorpal()(filtered_data()$OBS_VALUE),
fillOpacity = 0.6,
weight = 2,
color = "white",
popup = ~paste("Country: ", filtered_data()$CountryCode, "<br>",
"Freight Mode: ", filtered_data()$tra_mode, "<br>",
"Percent: ", filtered_data()$OBS_VALUE)
)
})
# Observe changes in filtered_data and update the map
observe({
pal <- colorpal()
Expand All @@ -112,5 +112,4 @@ output$map <- renderLeaflet({
# Run the Shiny app
shinyApp(ui, server)
```

0 comments on commit cb9a91c

Please sign in to comment.