shinydashboardrcharts

Shiny dashboard multiple charts - overlapping


I am using shiny dashboard package for my app. while trying to display 2 plots on the same page (each one in a box) they are overlapping. Also tried to use fluidRow for each plot - but still it seems both plot are connected to the same box (and overlapping)

This is my code:

 mainPanel(
  fluidRow( 
     box(showOutput("MeasuresPlot","morris"),width=6,title="Graph"),
     box(showOutput("ImportPlot","morris"),width=6,title="Graph2")
   )      
  )

Solution

  • Your almost there, inside your fluid row you can use columns like this:

    library(shiny)
    library(shinydashboard)
    
    
    ui <-dashboardPage(
        dashboardHeader(),
        dashboardSidebar(),
        dashboardBody(
          fluidRow(
            column(6,box(plotOutput("plt1"),width=12,title="Graph",background ="green") ),
            column(6,box(plotOutput("plt2"),width=12,title="Graph2",background="yellow") )
          ),
          fluidRow( actionButton("plot","plot") )
        )
    )
    
    server <- shinyServer(function(input, output, session) {
      observeEvent(input$plot,{
        output$plt1 <- renderPlot({plot(runif(100),runif(100))})
        output$plt2 <- renderPlot({plot(runif(100),runif(100))})
      })
    })
    
    shinyApp(ui = ui, server = server)
    

    The maximum width of a fluidRow is 12 so setting each column to have width 6 gives 2 equal width plots.