6

This question is a follow-up to How can put multiple plots side-by-side in shiny r? and R Shiny layout - side by side chart and/or table within a tab.

Is it possible to embed two side-by-side plots in a tab panel when there are other outputs present besides the two plots I want to embed side-by-side? I have tried every suggestion offered in the answers to the previous two questions and nothing works. No matter what I try I end up breaking my program so it refuses to display any out put at all.

mainPanel(
width = 10,
tabsetPanel(
  tabPanel("Dashboard", textOutput("text30"), textOutput("text31"), textOutput("text28"), textOutput("text29"), 
           column(6, plotOutput("plot1st"), column(6, plotOutput("plot2nd")), #what do I put here to make this work?
plotOutput("plot3rd"), plotOutput("plot9th"), plotOutput("plot4th"), plotOutput("plot8th"), plotOutput("plot7th"), plotOutput("plot6th")),
  tabPanel("Graph Switcher", plotOutput("selected_graph"))
))))

Is there anything I can do to make this work?

Update: Thanks to Florian's answer I was able to make the app look the way I wanted. However, as can be seen in the screenshot below, a small number 12 appears in between the plots, and the plots are not perfectly horizontally aligned. I'm wondering if it's possible to fix this?

enter image description here

Jennifer B.
  • 163
  • 1
  • 4
  • 10

1 Answers1

12

You can put multiple column elements in one fluidRow:


enter image description here


Hope this helps!

library(shiny)

ui <- fluidPage(
  tabsetPanel(
    tabPanel("Dashboard",
             fluidRow(12,
                      column(6,plotOutput('plot1')),
                      column(6,plotOutput('plot2'))
                      ),
             fluidRow(12,
                      column(4,plotOutput('plot3')),
                      column(4,plotOutput('plot4')),
                      column(4,plotOutput('plot5'))
                       ),
             fluidRow(12,
                      column(3,plotOutput('plot6')),
                      column(3,plotOutput('plot7')),
                      column(3,plotOutput('plot8')),
                      column(3,plotOutput('plot9'))

             )
    )))

server <- function(input,output)
{

  lapply(seq(10),function(x)
    {
    output[[paste0('plot',x)]] = renderPlot({hist(runif(1:20))})
  })
}

shinyApp(ui,server)
Florian
  • 24,425
  • 4
  • 49
  • 80
  • @J0ki, I am not quite sure what you mean by that. Please consider opening a new Stack Overflow question for that where you can elaborate. – Florian Apr 20 '18 at 11:38
  • @J0ki, if it is a duplicate question, than the answer should also be duplicate? I am really not sure what the difference is. You can put fluidRows and columns inside tabPanels, if that is what you are asking? – Florian Apr 20 '18 at 11:42
  • @JenniferB. I know this is old and I'm sure you found the answer already but I used this to help me and to solve your question in the update.. all you have to do is take away the 12 in the fluidRow. – NBE Jun 20 '19 at 17:42