Shiny的tabsetPanel不显示多个选项卡中的图 [英] Shiny's tabsetPanel not displaying plots in multiple tabs

查看:344
本文介绍了Shiny的tabsetPanel不显示多个选项卡中的图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ShinytabsetPanel中使用多个tabPanel控件.可以说,我使用以下代码仅从一个标签开始:

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?

推荐答案

您将"distPlot"分配给plotOutput的参数outputId. "ID"表示此值在整个有光泽的应用程序中必须是唯一的.不过,您可以将相同的图分配给两个不同的plotOutput:

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") )
    )
  ))
))

这篇关于Shiny的tabsetPanel不显示多个选项卡中的图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆