R闪亮的布局挣扎

时间:2018-10-11 14:53:06

标签: r layout shiny shinydashboard

我一直在浏览页面和结果页面,但似乎无法正常工作。 下面是我希望仪表板外观的粗略图。 下面的代码显示了我尝试过的几件事,希望有一些明显的我所缺少的东西。我越来越近了,但是我可以使用诸如流体列之类的方法,或者因为表1比第一个ggplot输出长的东西

R Shiny Layout

dashboardBody(
                      column(width = 2,
                             fluidRow(tableOutput('ptable')),
                             fluidRow(tableOutput('ptable'))),
                      column(width = 10,
                             fluidRow(plotOutput("Calplot")),
                             fluidRow(plotOutput("CalHeat")))

fluidRow(
                          column(width = 2, tableOutput('ptable')),
                          column(width = 10, plotOutput("Calplot"))
                        ),
                      fluidRow(
                          column(width = 2, tableOutput('ctable')),
                          column(width = 10, plotOutput("CalHeat"))
                          )

1 个答案:

答案 0 :(得分:2)

也许您想尝试基于列的布局。可以找到很好的解释here。 本示例将columnbox结合在一起,您可以在其中定义每个对象的宽度。
我还切换到DT表,因为我发现它们更强大,更易于样式设置,例如options = list(scrollX = TRUE, pageLength = 12),它可以很好地呈现表并向表中添加滚动条。如果您删除此选项,则表格和绘图将覆盖。

library(shiny)
library(shinydashboard)
library(DT)

ui = dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sliderInput("obs", "Number of observations:", min = 0, max = 1000, value = 500),  
    sliderInput("obs1", "Number of observations:", min = 0, max = 1000, value = 500),  
    sliderInput("obs2", "Number of observations:", min = 0, max = 1000, value = 500)  
  ),
  dashboardBody(
    column(width = 12,
           box(width = 3, DT::dataTableOutput('table1'),
               DT::dataTableOutput('table2')),

           box(width = 9, plotOutput("plot2"),
               plotOutput("plot1"))
    )
  )
)

server = function(input, output) { 
  output$table1 <- DT::renderDataTable({
    datatable(mtcars, caption = "table1",
              options = list(scrollX = TRUE,
              pageLength = 12))
  }) 
  output$table2 <- DT::renderDataTable({
    datatable(mtcars[,1:3], caption = "table2")
  })  

  output$plot1 <- renderPlot({
    plot(mtcars$mpg, mtcars$cyl, main = "plot1")
  })  
  output$plot2 <- renderPlot( {
    plot(mtcars$mpg, mtcars$cyl, main = "plot2")
  })  

}

shinyApp(ui, server)

enter image description here

相关问题