我正在创建一个shiny 的仪表板应用程序,仪表板主体应该显示一些 map .到目前为止,让 map 扩展到身体的整个宽度没有问题,但它不知何故不愿意调整到整个高度.

传单本身已经设置为覆盖100%的高度,但它没有做到这一点.当我为传单输出使用"高度"属性时,传单对象将完全不显示,而我只剩下一个空框.

代码如下所示:

library(shinydashboard)
library(leaflet)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(
    sidebarMenu(
      menuItem(
        "Maps", 
        tabName = "maps", 
        icon = icon("globe"),
        menuSubItem("Watersheds", tabName = "m_water", icon = icon("map")),
        menuSubItem("Population", tabName = "m_pop", icon = icon("map"))
      ),
      menuItem(
        "Charts", 
        tabName = "charts", 
        icon = icon("bar-chart"),
        menuSubItem("Watersheds", tabName = "c_water", icon = icon("area-chart")),
        menuSubItem("Population", tabName = "c_pop", icon = icon("area-chart"))
      )
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(
        tabName = "m_water",
        box(
          title = "Baltic catchment areas",
          collapsible = TRUE,
          width = "100%",
          height = "100%",
          leafletOutput("l_watershed")
        )
      ),
      tabItem(
        tabName = "m_pop",
        # Map in Dashboard
        leafletOutput("l_population")
      ),
      tabItem(
        tabName = "charts",
        h2("Second tab content")
      )
    )
  )
)

server <- function(input, output) {
  set.seed(122)
  histdata <- rnorm(500)

  output$l_watershed <- renderLeaflet({
    leaflet(height = "100%") %>% addTiles() %>% setView(19.08, 60.25, zoom = 4) %>%addWMSTiles(
      "http://62.236.121.188/arcgis/services/DataAndMaps/Background/MapServer/WMSServer?",
      layers = "11",
      options = WMSTileOptions(
        format = "image/png",
        transparent = TRUE
      ),
      attribution = "Catchment area provided by HELCOM"
    )
  })

  output$l_population <- renderLeaflet({
    leaflet(height = "100%") %>% addTiles() %>% setView(19.08, 60.25, zoom = 4) %>%addWMSTiles(
      "http://62.236.121.188/arcgis/services/DataAndMaps/Background/MapServer/WMSServer?",
      layers = "17",
      options = WMSTileOptions(
        format = "image/png",
        transparent = TRUE
      ),
      attribution = "Population data provided by HELCOM"
    )
  })
}

shinyApp(ui, server)

推荐答案

我个人发现,相对于窗口大小设置高度更令人满意.高度百分比不起作用,因为仪表板主体的高度未定义.但是相对于整个文件来说是可以的.

100%的仪表板主体采用100vh(ccs3单元)减go 表头(最小50px)减go 仪表板主体填充(2*15px).

所以,将高度设置为100vh-80px,你应该会没事的.

由于Shinny不支持css3单元,因此必须将其直接包含在文档中,如下面的代码所示.

library(shiny)
library(shinydashboard)
library(leaflet)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    tags$style(type = "text/css", "#map {height: calc(100vh - 80px) !important;}"),
    leafletOutput("map")
  )
)

server <- function(input, output) {
  output$map <- renderLeaflet({
    leaflet() %>% addTiles() %>% setView(42, 16, 4)
  })
}

runApp(shinyApp(ui, server), launch.browser = TRUE)

玩得高兴

R相关问答推荐

在数据表中呈现数学符号

如何创建构成多个独立列条目列表的收件箱框列?

更改Heatmap Annotation对象的名称

如何使用R中的dhrr函数将李克特量表的因子列从长转换为宽?

随机森林回归:下拉列重要性

任意列的欧几里得距离

R for循环返回到先前值

如何动态更新selectizeInput?

如何通过判断数据框的一列来压缩另一列?

R Select()可以测试不存在的子集列

跨列查找多个时间报告

基于数据集属性将科分配给物种

如何在PDF格式的kableExtra表格中显示管道字符?

有没有办法将基于每个值中出现的两个关键字或短语的字符串向量重新编码为具有这两个值的新向量?

网络抓取新闻标题和时间

我需要使用ggplot2制作堆叠条形图

对R中的列表列执行ROW Mean操作

当由base::限定时,`[.factor`引发NextMethod错误

使用卡环从R中的列中删除单位(&C)

如何使用包含要子集的值的列表或数据框来子集多个列?