我需要制作一个非常专业的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)
答案 0 :(得分:0)
因此,我不得不检查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的图输出 :
fluidRow(
column(12, offset = 1,
plotlyOutput("plot_sesiones_por_mes", height = "500px"))),
br(),
流体行高度500px :
fluidRow(style = "height:500px",
column(12, offset = 1,
plotlyOutput("plot_sesiones_por_mes"))),
br(),