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?
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 plotOutput
s 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") )
)
))
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With