R语言 bs4Dash盒子里的传单Map

qxsslcnc  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(75)

最近,当我在一个闪亮的 Jmeter 板上工作时,我遇到了一个问题,即Leaflet map不能(似乎)正确地与bs4Dash box一起工作。似乎在最大化盒子后,活页Map没有更新以反映新的容器宽度。
Map after maximizing the box
我认为这是一个类似的问题:rstudio/leaflet#248 .尝试了Joe Cheng提供的解决方案,但无法使其工作(不幸的是,我不擅长JavaScript)。在最大化盒子后,有没有什么解决方法可以让Map全屏渲染?
可重复的示例:

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)
wswtfjt7

wswtfjt71#

您可以为框定义id,然后在服务器端定义updateBox来更改宽度。试试这个

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

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    bs4Dash::box(
      id = "mybox", 
      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()
  })
  
  observeEvent(input$mybox$maximized, {
    if (input$mybox$maximized){
      mywidth = 12
    } else mywidth = 6
    updateBox(
      "mybox",
      action = "update",
      options = list(
        width = mywidth
      )
    )
  })
  
}

shinyApp(ui, server)

相关问题