rstudio / rstudio/flexdashboard
Output flexdashboard with renderLeaflet to html
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 848
- Forks
- 298
- PR merge metrics
- No merged PRs in 30d
Description
source: Output flexdashboard with renderLeaflet to html
I have flexdashboard code that works when I run it within RStudio (using the "Run Document" button and viewing in RStudio's viewer - and also when clicking the "Open in Browser" button in viewer, it opens a system browser and works fine). However, if I use rmarkdown::render() to output it to an html file, the reactive leaflet maps no longer work and are blank. The maps that are output using leaflet() work, but not renderLeaflet().
for example:
---
title: "Project Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
runtime: shiny
---
```{r setup}
library(tidyverse)
library(sf)
library(leaflet)
library(flexdashboard)
library(shiny)
```{r data}
# Create the data
cities_data <- data.frame(
Name = c("City A", "City B", "City C"),
Latitude = c(40.7128, 34.0522, 51.5074),
Longitude = c(-74.0060, -118.2437, -0.1278)
) %>%
st_as_sf(coords = c("Longitude", "Latitude")) %>%
st_set_crs(4326)
Column {data-width=100}
```{r}
selectInput("Name", label = "Select City",
choices = c("\n", unique(as.character(cities_data$Name))),
selected = "\n",
width = "100%")
Column {.tabset .tabset-fade}
### Individual Cities
```{r}
# Reactive leaflet map
renderLeaflet({
leaflet() %>%
addProviderTiles(providers$Esri.WorldImagery,
group = "Esri.WorldImagery") %>%
addCircleMarkers(data = cities_data %>% filter(Name == input$Name),
color = "blue")
})
### All Cities
```{r}
## Leaflet map (non-reactive)
Map <- leaflet(data = cities_data) %>%
addProviderTiles(providers$Esri.WorldTopoMap) %>%
addCircleMarkers(color = "red")
Map
f I run this example code with rmarkdown::render(input = "xxx.Rmd", output_file = "xxx.html"), the selectable Individual Cities maps do not work in the output html file, but the All Cities map works fine. I am guessing the shiny::selectInput() does not play well with renderLeaflet() in a flexdashboard scenario. Does anyone have a solution for this?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied flexdashboard example with rmarkdown::render() and compare its renderLeaflet/selectInput behavior with Run Document. Investigate the flexdashboard runtime and Shiny/Leaflet integration; done when the Individual Cities reactive map works in generated HTML while the All Cities map remains functional.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100