【问题标题】:tab dependent sidebars in shiny dashboard闪亮仪表板中的选项卡相关侧边栏
【发布时间】:2015-05-19 17:06:11
【问题描述】:

我有一个闪亮的仪表板,它有三个使用tabBox 的选项卡,我想使用激活的选项卡来确定/显示相关的仪表板侧边栏输入。目前它们都同时出现...我希望根据激活的选项卡消失一些。

以下是我目前的尝试。

对此的任何帮助将不胜感激。

我的ui.R脚本如下:

#ui.R
library(shiny)
library(shinydashboard)

header <- dashboardHeader(
  title = 'Simple dashbaord'
)
body <- dashboardBody(
  fluidRow(
    column(width=12,
           tabBox(
             id='tabvals',
              width=NULL,
              tabPanel('TAB name1',
                       plotOutput('plot1'),value=1),
              tabPanel('TAB name2',
                       plotOutput('plot2'),value=2),
              tabPanel('TAB name3',
                       plotOutput('plot3'),value=3)
            )
     ) 
   )
)


dashboardPage(
   header,
   dashboardSidebar(
    conditionalPanel(
      condition = "input$tabvals == 1",
      sliderInput('slider1','Slider for tab1:',min=1,max=3000,value=30),
      sliderInput('slider2','2nd Slider for tab1:',min=1,max=3000,value=300)
     ),
    conditionalPanel(
      condition = "input$tabvals == 2",
      sliderInput('slider3','Slider for tab2:',min=1,max=1000,value=10), 
      sliderInput('slider4','2nd Slider for tab2:',min=1,max=1000,value=500)
    ),
    conditionalPanel(
      condition = "input$tabvals == 3",
      sliderInput('slider5','Slider for tab3:',min=1,max=3000,value=30),
      sliderInput('slider6','2nd Slider for tab3:',min=1,max=3000,value=30)
    )
   ),
  body
)

我的server.R脚本如下:

require(shiny)
require(ggplot2)

shinyServer(function(input,output){

  output$plot1 <- renderPlot({

    out <- ggplot(data.frame(X1=rnorm(input$slider1,input$slider2)),aes(X1))+
      geom_density(fill='light blue')+
      theme_minimal()+
      xlab('X value')+
      ylab('')+
      ggtitle('Distribution of X')+
      theme(
        axis.text.y = element_blank(),
        axis.ticks = element_blank())

    print(out)
   })
   output$plot2 <- renderPlot({
     out <- ggplot(data.frame(X1=rnorm(input$slider3,input$slider4)),aes(X1))+
      geom_density(fill='light blue')+
      theme_minimal()+
      xlab('X value')+
      ylab('')+
      ggtitle('Distribution of X')+
      theme(
         axis.text.y = element_blank(),
         axis.ticks = element_blank())

     print(out)
   })
  output$plot3 <- renderPlot({
    out <- ggplot(data.frame(X1=rnorm(input$slider5,input$slider6)),aes(X1))+
      geom_density(fill='light blue')+
      theme_minimal()+
      xlab('X value')+
      ylab('')+
      ggtitle('Distribution of X')+
      theme(
         axis.text.y = element_blank(),
         axis.ticks = element_blank())

     print(out)
   })


})

【问题讨论】:

  • 尝试在conditonalPanel 的条件中将$ 替换为.input.tabvals 而不是input$tabvals),请参阅Details 段落here
  • 谢谢!我自己也试过了……

标签: r shiny


【解决方案1】:

改变条件:

condition = "input$tabvals == 1",

到:

condition = "input.tabvals == 1",

帮助。这是否应该在 Shiny 中更加一致?

【讨论】:

    猜你喜欢
    • 2016-11-24
    • 2020-10-21
    • 2018-12-24
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    • 2018-09-25
    相关资源
    最近更新 更多