Search code examples
rshinyr-leaflet

Create an adjustable R leaflet with dashboard


I'm trying to create a leaflet-image within a Dashboard. This is a screenshot of what I have so far:

enter image description here

My problem is obviously that the map height is reduced too much. How can a fix the height of the leaflet chart (to be more appealing with or without the separate sidebar)?

That's my code:

---
title: "Untitled"
runtime: shiny
output: flexdashboard::flex_dashboard # !!!
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(leaflet)

qty_d <- tibble(latt = c(50, 53),
                long = c(10, 16),
                qty = c(200, 140),
                planttext = c("AAA", "BBB"))
```

Page 1
======

Column1 {.sidebar}
------------------------------------------------
```{r}
sliderInput("bubblesize",
            label = "Bubble Size",
            min = 0.01, max = 0.1, value = 0.05, step = 0.02)

```

Column2 {}
-----------------------

```{r, echo=FALSE}
renderLeaflet({
  my_size <- input$bubblesize
  leaflet() %>%
  addTiles() %>%
  addCircleMarkers(lng = ~long, lat = ~latt, 
                   popup = ~planttext,
                   radius = ~qty * my_size, data = qty_d)
})
```

Solution

  • There's a similar question at this link.

    A solution for your flexdashboard would be to replace your column2 code with:

    ```{r, echo=FALSE}
    output$mymap = renderLeaflet({
      my_size <- input$bubblesize
      leaflet() %>%
      addTiles() %>%
      addCircleMarkers(lng = ~long, lat = ~latt, 
                       popup = ~planttext,
                       radius = ~qty * my_size, data = qty_d)
    })
    
    leafletOutput('mymap', height=1000)
    ```