【问题标题】:Shinydashboard: height issue even using fluidRowShinydashboard:即使使用fluidRow也有高度问题
【发布时间】:2018-09-15 19:17:43
【问题描述】:

我需要制作一个非常专业的 Shinyapp,但是应用程序主体的结尾在最后一个情节的中间结束。

我发现了另一个问题,但它的解决方案(使用fluidRow)在我的情况下不起作用:

https://stackoverflow.com/questions/46259208/shiny-dashboard-mainpanel-height-issue

可能出了什么问题?

所有数据都是可重现的。

## app.R ##
library(shiny)
library(shinydashboard)
library(dygraphs)
library(plotly)
library(readr)


ui <- dashboardPage(
  dashboardHeader(title = "Monitoramento Banco de Dados"),         
  dashboardSidebar(
    sliderInput("DateInput", "Periodo", -30, 0, c(-15, 0), pre = "D.")
  ),
  dashboardBody(

    fluidRow(
      dygraphOutput("plot1"),
      br(),
      plotlyOutput("plot")
    )
  )
)

server <- function(input, output) {



  output$plot1 <- renderDygraph({
    lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
    dyRangeSelector(dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)"), dateWindow = c("1974-01-01", "1980-01-01"))
  }) 


  sesiones_por_fuente <- reactive({


#sesiones_ga <- read_csv("www/ga-sesiones-lc-20180824.csv", skip = 0)
sesiones_ga <- read_csv("https://www.dropbox.com/s/w2ggnb0p4mz2nus/sesiones-2018.csv?dl=1", skip = 0)

    sesiones_ga <- sesiones_ga %>%
      group_by(date, sources) %>%
      summarise(sessions = sum(sessions)) %>%
      filter(sources != "spam")


  })



  m <- list(
    l = 120,
    r = 120,
    b = 100,
    t = 100,
    pad = 20
  )

  output$plot <- renderPlotly({

plot_ly(sesiones_por_fuente(), x = ~sessions, y = ~sources, type = 'bar',
        width = 1200, height = 500, orientation = 'h') %>%
  layout(title = "Sesiones por mes",
         xaxis = list(title = ""),
         yaxis = list(title = ""),
         margin = m) %>%
  layout(hovermode = 'compare',
         separators = ',')




})

}

shinyApp(ui, server)

【问题讨论】:

    标签: r shinydashboard


    【解决方案1】:

    所以我不得不检查 Shiny 生成的 HTML。其结果是,绘图图呈现在一个 div(由 server.R 文件生成)中,而这个 div 在另一个 div 中(由 ui.R 生成)。

    因此,如果 sever.R 文件生成的内部 div 大于 ui.R 文件生成的 div,则会产生该布局错误。

    所以,如果你在 server.R 中有这个(注意 plot_ly fun() 中的 500px 高度参数)

      output$plot <- renderPlotly({
    
    
    sesiones_fuente <- sesiones_por_fuente() %>%
      filter(date > input$dateRange[1], date < input$dateRange[2]) %>%
      group_by(sources) %>%
      summarise(sessions = sum(sessions))
    
    plot_ly(sesiones_fuente, x = ~sessions, y = ~sources, type = 'bar',
            width = 1200, height = 500, orientation = 'h') %>% 
          layout(title = "Sesiones por mes",
                 xaxis = list(title = ""),
                 yaxis = list(title = ""),
                margin = m) 
    
    
    })
    

    你需要在plotlyOutput中使用参数height=500px或者在ui.R中使用相同高度的Fluidrow

    高度为 500px 的 plotlyOutput

    fluidRow(
                column(12, offset = 1,
                       plotlyOutput("plot_sesiones_por_mes", height = "500px"))),
                br(),
    

    高度为 500 像素的流体行

    fluidRow(style = "height:500px",
                column(12, offset = 1,
                       plotlyOutput("plot_sesiones_por_mes"))),
                br(),
    

    【讨论】:

      猜你喜欢
      • 2013-10-21
      • 2011-11-19
      • 1970-01-01
      • 2021-06-11
      • 2021-10-28
      • 2020-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多