Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny's tabsetPanel not displaying plots in multiple tabs

Tags:

plot

tabs

r

shiny

I am trying to use multiple tabPanel controls within the tabsetPanel in Shiny. Lets say I start with only one tab using the following code:

mainPanel(
    tabsetPanel(
    tabPanel("Plot",plotOutput("distPlot"))
    )

The code runs fine and displays the plot in the tab.

But the moment I introduce another tab just to test the tabs out, both the tabs stop displaying any plots at all. I am using the following code:

mainPanel(
    tabsetPanel(
    tabPanel("Plot",plotOutput("distPlot")),
    tabPanel("Plot",plotOutput("distPlot"))
    )

Please note that I am trying to display the same plot in both tabs just to test if the tabs work. All I get are two blank tabs (if I use only one tab, the plot displays properly).

Would someone please be able to help me figure this out?

like image 885
Patthebug Avatar asked Apr 08 '14 04:04

Patthebug


1 Answers

You assign "distPlot" to plotOutput's parameter outputId. "ID" indicates that this value has to be unique over the entire shiny app. You can assign the same plot to two different plotOutputs though:

runApp( list(

  server = function(input, output) {
    df <- data.frame( x = rnorm(10), y = rnorm(10) )
    output$distPlot1 <- renderPlot({ plot( df, x ~ y ) })
    output$distPlot2 <- renderPlot({ plot( df, x ~ y ) })
  },

  ui = fluidPage( mainPanel(
    tabsetPanel(
      tabPanel( "Plot", plotOutput("distPlot1") ),
      tabPanel( "Plot", plotOutput("distPlot2") )
    )
  ))
))
like image 198
Beasterfield Avatar answered Oct 06 '22 12:10

Beasterfield