Reputation: 37
I've been flicking through pages and pages of results but can't seem to get this working. Below is a crude paint diagram of how I want my dashboard to look. The code below shows a couple of things that I have tried, hopefully there is something obvious I'm missing. I'm getting close but I could do with something like a fluid column or something as table 1 is longer than the 1st ggplot output
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"))
)
Upvotes: 2
Views: 1425
Reputation: 9809
Maybe you want to try a column-based layout. A very good explanation can be found here.
This example combines column
with box
, where you can define the width for each object.
I also switched to DT
tables, as I find them more powerful and easy to style, for example the options = list(scrollX = TRUE, pageLength = 12)
, which renders the table nicely and adds a scroller to the table. If you would remove this option, the table and plot would overlay.
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)
Upvotes: 4