【问题标题】:R Shiny Single Plot to Fill Entire Dashboard PageR Shiny Single Plot 填充整个仪表板页面
【发布时间】:2023-04-08 07:15:01
【问题描述】:

我已经构建了一个图,我想填充闪亮仪表板的整个页面。基本上下面的代码对我有用,除了图表总是页面高度的一半,我希望它填满整个高度。我已经尝试在这个论坛上使用 fillPage() 函数和其他解决方案,但似乎没有一个适合我的特定情况。

下面是一些可重现的代码及其生成的图像。谢谢。

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
    dashboardHeader(title = "Header"),

    sidebar <- dashboardSidebar(),
    body <- dashboardBody(
        fillPage(plotlyOutput("Waterfall", height="100%", width="100%"))
    ),
    dashboardPage(dashboardHeader(title="Title"), sidebar,body)
)
server <- shinyServer(function(input, output, session) {
    
  x= list("Sales", "Consulting", "Net revenue", "Purchases", "Other expenses", "Profit before tax")
  measure= c("relative", "relative", "total", "relative", "relative", "total")
  text= c("+60", "+80", "", "-40", "-20", "Total")
  y= c(60, 80, 0, -40, -20, 0)
  data = data.frame(x=factor(x,levels=x),measure,text,y)
  
  output$Waterfall <- renderPlotly({ plot_ly(
    data, name = "20", type = "waterfall", measure = ~measure,
    x = ~x, textposition = "outside", y= ~y, text =~text,
    connector = list(line = list(color= "rgb(63, 63, 63)")))   })
})
  
shinyApp(ui=ui, server=server)

Fill Page

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    我添加了一个 CSS 行

    tags$style(type = "text/css", "#Waterfall {height: calc(100vh - 80px) !important;}"),
    

    在这个部分

     fillPage(
          tags$style(type = "text/css", "#Waterfall {height: calc(100vh - 80px) !important;}"),
          plotlyOutput("Waterfall", height="100%", width="100%"))
      ),
    

    这应该可行:

    library(shiny)
    library(shinydashboard)
    library(plotly)
    
    ui <- dashboardPage(
      dashboardHeader(title = "Header"),
      
      sidebar <- dashboardSidebar(),
      body <- dashboardBody(
        fillPage(
          tags$style(type = "text/css", "#Waterfall {height: calc(100vh - 80px) !important;}"),
          plotlyOutput("Waterfall", height="100%", width="100%"))
      ),
      dashboardPage(dashboardHeader(title="Title"), sidebar,body)
    )
    server <- shinyServer(function(input, output, session) {
      
      x= list("Sales", "Consulting", "Net revenue", "Purchases", "Other expenses", "Profit before tax")
      measure= c("relative", "relative", "total", "relative", "relative", "total")
      text= c("+60", "+80", "", "-40", "-20", "Total")
      y= c(60, 80, 0, -40, -20, 0)
      data = data.frame(x=factor(x,levels=x),measure,text,y)
      
      output$Waterfall <- renderPlotly({ plot_ly(
        data, name = "20", type = "waterfall", measure = ~measure,
        x = ~x, textposition = "outside", y= ~y, text =~text,
        connector = list(line = list(color= "rgb(63, 63, 63)")))   })
    })
    
    shinyApp(ui=ui, server=server)
    

    类似问题:Basic example of fillPage in Shiny - How does it work?

    【讨论】:

    • 你是冠军!那完成了工作。你知道,我在这里看到了另一个帖子,解决方案是你添加的那一行代码,但不清楚它是否需要进入 fillPage 函数。那是关键。谢谢。
    • 很高兴知道它成功了 :) 顺便说一句,你的情节看起来很棒。
    猜你喜欢
    • 2017-09-27
    • 2020-04-02
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-14
    • 1970-01-01
    相关资源
    最近更新 更多