Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output flexdashboard with renderLeaflet to html #446

Open
Otoliths opened this issue Oct 19, 2023 · 0 comments
Open

Output flexdashboard with renderLeaflet to html #446

Otoliths opened this issue Oct 19, 2023 · 0 comments

Comments

@Otoliths
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant