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

Leaflet map width after maximizing box #364

Open
marcin-karlinski opened this issue Oct 6, 2023 · 1 comment
Open

Leaflet map width after maximizing box #364

marcin-karlinski opened this issue Oct 6, 2023 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@marcin-karlinski
Copy link

Hi. First of all, thank you for a great package.

Recently, when working on a dashboard, I encountered an issue of Leaflet map not working (seemingly) correctly with bs4Dash box. Seems that after the box is maximized, leaflet map is not updating to reflect the new container width. I think this is a similar issue to this one: rstudio/leaflet#248. Tried a solution provided by Joe Cheng, but couldn't make it work (I'm not good at Javascript unfortunately).

image
Not completely sure if this is an issue with bs4Dash or not, but any help would be appreciated.

A reproducible example:

library(shiny)
library(bs4Dash)
library(leaflet)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    box(
      title = "Map",
      collapsible = TRUE,
      height = "80vh",
      width = 6,
      maximizable = TRUE,
      leafletOutput("map1", height = "100%")
    )
  )
)

server <- function(input, output, session) {
  output$map1 <- renderLeaflet({
    leaflet() %>% 
      setView(19.08, 60.25, zoom = 4) %>% 
      addTiles()
  })
  
}

shinyApp(ui, server)

@AshesITR
Copy link

See #146

library(shiny)
library(bs4Dash)
library(leaflet)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    tags$head(
      tags$script(
        "$(function() {
          $('[data-card-widget=\"maximize\"]').on('click', function() {
            $('#map1').trigger('resize');
          });
        });
        "
      )
    ),
    box(
      title = "Map",
      collapsible = TRUE,
      height = "80vh",
      width = 6,
      maximizable = TRUE,
      leafletOutput("map1", height = "100%")
    )
  )
)

server <- function(input, output, session) {
  output$map1 <- renderLeaflet({
    leaflet() %>%
      setView(19.08, 60.25, zoom = 4) %>%
      addTiles()
  })

}

shinyApp(ui, server)

@DivadNojnarg DivadNojnarg added the duplicate This issue or pull request already exists label Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants