首页 > 解决方案 > 如何在 Shiny Dashboard 中使用 fillPage

问题描述

我无法在 R 中使用 Shiny 使地图显示为全屏。任何帮助将不胜感激,谢谢。

我在 ui 和服务器端都玩过各种 height = "100%" 和 height = "auto"。这些已经在 fillPage、fillCol、fillRow、outputPlot 和 renderPlot 函数中进行了尝试。

如果我使用 height = "400px" 等,我可以强制执行某些操作,但是当将仪表板从笔记本电脑屏幕移动到更大的东西等时,这通常不会提供任何东西。

我提供了简化版本的代码。它包含我在“真实”版本中的 css 样式,因为我的理解是 css 也可能影响 R 代码。

library(shiny)
library(shinydashboard)
library(ggplot2)

ui <- dashboardPage(
  dashboardHeader(title = "SOS"),
  dashboardSidebar(
    br()
  ),
  dashboardBody(tags$body(tags$style(HTML('
                              /* logo */
                                          .skin-blue .main-header .logo {
                                          background-color: #0a22d8;
                                          }

                                          /* logo when hovered */
                                          .skin-blue .main-header .logo:hover {
                                          background-color: #8390ef;
                                          }

                                          /* navbar (rest of the header) */
                                          .skin-blue .main-header .navbar {
                                          background-color: #0a22d8;
                                          }        

                                          /* main sidebar */
                                          .skin-blue .main-sidebar {
                                          background-color: #0a22d8;
                                          }

                                          /* active selected tab in the sidebarmenu */
                                          .skin-blue .main-sidebar .sidebar .sidebar-menu .active a{
                                          background-color: #ff0000;
                                          }

                                          /* other links in the sidebarmenu */
                                          .skin-blue .main-sidebar .sidebar .sidebar-menu a{
                                          background-color: #00ff00;
                                          color: #000000;
                                          }

                                          /* other links in the sidebarmenu when hovered */
                                          .skin-blue .main-sidebar .sidebar .sidebar-menu a:hover{
                                          background-color: #ff69b4;
                                          }
                                          /* toggle button when hovered  */                    
                                          .skin-blue .main-header .navbar .sidebar-toggle:hover{
                                          background-color: #8390ef;
                                          }

                                         /* my atmpt background   */
                                          .skin-blue .content {background-color: #8390ef;}'))),
                tabsetPanel(type = "tabs",
                            tabPanel("Help", 
                                     br(),
                                     fillPage(
                                       fillRow(plotOutput("my_map"))
                                     )))))

server <- function(input, output, session){

  output$my_map <- renderPlot({
    wrld <- map_data("world")

    ggplot(wrld,  color = "white") +
      geom_polygon(aes(x = long, y = lat, group = group)) +
      coord_fixed(1.3) +
      guides(fill = F)
  })
}

shinyApp(ui, server)

标签: cssrggplot2shinyshinydashboard

解决方案


您能否提供以下属性(您可以使用您的课程而不是 div)

 div{
    width:100%;
    height:100%;
    }

推荐阅读