首页 > 解决方案 > 如何让我的 R Shiny Dashboard 填满整个页面?

问题描述

我有一个正在使用的 R Shiny 应用程序shinydashboard,但在让 UI 填充浏览器窗口时遇到问题。

这是我的 ui.R 输出:

#
# This is the user-interface definition of a Shiny web application. You can
# run the application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
# 
#    http://shiny.rstudio.com/
#

## app.R ##
library(rsconnect)
library(shinydashboardPlus)
library(shinydashboard)
library(shiny)

#shinyApp(ui = ui, server = server, options = list(height = 1080))


ui <- dashboardPage(skin = "red",
  dashboardHeader(title = "Miradashboard",
                  # This drop-down menu offers user and system administration within the application
                  dropdownMenu(type = "messages",
                               messageItem(
                                 from = "Sales Dept",
                                 message = "Sales are steady this month."
                               ),
                               messageItem(
                                 from = "New User",
                                 message = "How do I register?",
                                 icon = icon("question"),
                                 time = "13:45"
                               ),
                               messageItem(
                                 from = "Support",
                                 message = "The new server is ready.",
                                 icon = icon("life-ring"),
                                 time = "2014-12-01"
                               )
                  ),
                  # This is a drop-down menu for checking notifications.
                  # This should alert users of alerts that have not been merged to a case in the last 15 days.
                  dropdownMenu(type = "notifications",
                               notificationItem(
                                 text = "5 new users today",
                                 icon("users")
                               ),
                               notificationItem(
                                 text = "12 items delivered",
                                 icon("truck"),
                                 status = "success"
                               ),
                               notificationItem(
                                 text = "Server load at 86%",
                                 icon = icon("exclamation-triangle"),
                                 status = "warning"
                               )
                  ),
                  # This is a drop-down menu for checking tasks.
                  # This drop-down menu will eventually offer suggestions based off of ML Algorithms.
                  dropdownMenu(type = "tasks", badgeStatus = "success",
                               taskItem(value = 90, color = "green",
                                        "Documentation"
                               ),
                               taskItem(value = 17, color = "aqua",
                                        "Project X"
                               ),
                               taskItem(value = 75, color = "yellow",
                                        "Server deployment"
                               ),
                               taskItem(value = 80, color = "red",
                                        "Overall project"
                               )
                  )



  ),
  dashboardSidebar(
    ## Sidebar content
    dashboardSidebar(
      sidebarMenu(
        menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
        menuItem("Widgets", tabName = "widgets", icon = icon("th")),
        menuItem("Reports", tabName = "reports", icon = icon("th")),
        menuItem("OpsCare Clients", tabName = "OpsCare Clients", icon = icon("bar-chart-o")),
        menuItem("ProdCare Clients", tabName = "ProdCare Clients", icon = icon("bar-chart-o")),
        menuItem("Alerts", tabName = "Alerts", icon = icon("bar-chart-o")),
        menuItem("Change Requests", tabName = "Change Requests", icon = icon("list-alt")),
        menuItem("Maintenance Windows", tabName = "Maintenance Windows", icon = icon("list-alt")),
        menuItem("Rundeck", tabName = "Rundeck", icon = icon("bars")),
        menuItem("Salesforce", tabName = "Salesforce", icon = icon("bars")),
        menuItem("Handovers", tabName = "Handovers", icon = icon("bars")),
        menuItem("Jump-Host Access", tabName = "Jump-Host Access", icon = icon("bars"))
      )
    )
  ),
  dashboardBody(
    # Boxes need to be put in a row (or column)
    fluidRow(
      box(plotOutput("plot1", height = 250)),
      box(plotOutput("plot2", height = 250)),
      box(plotOutput("plot3", height = 250)),
      #box(plotOutput("plot4", height = 250)),
      #box(dataTableOutput("DT1", height = 250)),
      box(
        title = "Controls",
        sliderInput("slider", "Number of observations:", 1, 100, 50)
      )
    )
  )
)

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

  # List Server Output whereby plot[1-#] is the plot box output in UI above.
  # Server Output occurds and is defined by data variables
  # histdata[seq_len(input$slider)] defines slider utilization
  # hist(data) defines histogram off of "data"te
  output$plot1 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })
  output$plot2 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })
  output$plot3 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })
  output$plot4 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })
  output$plot5 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })
}

shinyApp(ui, server)

正如您在所附图片中看到的那样,该页面在 Web 浏览器中被截断。我的最终目标是将它扩展到全屏,因为我试图让内部用户可以使用和访问它。如果有人对如何将仪表板页面扩展到全尺寸有任何建议,那就太好了。

在尝试自己解决它方面,我研究了以下方面以将其扩展到全屏。

  1. 我查看了 shiny.js 但这似乎不是标准的存储库或通过 CRAN 安装
  2. 我查看了 fillPage 功能,但这使它成为 HTML 并且上面的代码不是 HTML 格式
  3. 我已经研究过调用填充页面功能,但它并没有在网络浏览器的完整页面视图中这样做。调用的命令放置在 ui <-dashboardPage 定义之后的 ad 之前 ui.R

屏幕截图显示 UI 被切到窗口的一半

标签: rshinyshinydashboard

解决方案


我运行你的代码,它全屏显示。这是我shinyapp.io 帐户上的应用程序。

也许您必须检查应用程序版本。这是我拥有的软件包版本。我使用的是 R 版本 3.5.2 (2018-12-20) 和 RStudio 1.1.463。

R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

other attached packages:
 [1] shinydashboard_0.7.1     shinydashboardPlus_0.6.0 rsconnect_0.8.12        
 [4] shiny_1.2.0              forcats_0.3.0            stringr_1.3.1           
 [7] dplyr_0.7.5              purrr_0.2.4              readr_1.1.1             
[10] tidyr_0.8.1              tibble_1.4.2             ggplot2_3.0.0           
[13] tidyverse_1.2.1         

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.4 reshape2_1.4.3   haven_1.1.1      lattice_0.20-38 
 [5] colorspace_1.3-2 htmltools_0.3.6  yaml_2.2.0       utf8_1.1.4      
 [9] rlang_0.2.0      pillar_1.2.3     later_0.7.5      foreign_0.8-71  
[13] glue_1.3.0       withr_2.1.2      modelr_0.1.2     readxl_1.1.0    
[17] bindrcpp_0.2.2   bindr_0.1.1      plyr_1.8.4       munsell_0.4.3   
[21] gtable_0.2.0     cellranger_1.1.0 rvest_0.3.2      psych_1.8.4     
[25] httpuv_1.4.5.1   parallel_3.5.2   broom_0.4.4      Rcpp_1.0.0      
[29] xtable_1.8-2     openssl_1.0.1    promises_1.0.1   scales_0.5.0    
[33] jsonlite_1.6     mime_0.5         mnormt_1.5-5     hms_0.4.2       
[37] digest_0.6.18    stringi_1.1.7    grid_3.5.2       cli_1.0.0       
[41] tools_3.5.2      magrittr_1.5     lazyeval_0.2.1   crayon_1.3.4    
[45] pkgconfig_2.0.1  xml2_1.2.0       lubridate_1.7.4  assertthat_0.2.0
[49] httr_1.3.1       rstudioapi_0.7   R6_2.2.2         nlme_3.1-137    
[53] compiler_3.5.2  

我还在 RStudio 中尝试过“在窗口中运行”,它也可以全屏运行。

在此处输入图像描述


推荐阅读