【问题标题】:Shiny conditionalPanel shows all conditions on all tabs闪亮的条件面板显示所有选项卡上的所有条件
【发布时间】:2017-04-04 16:01:51
【问题描述】:

我是 Shiny 的新手,我有这个代码。我创建了 3 个 tabPanel。当我运行 Shiny 应用程序时 - 它在所有选项卡中显示所有条件集。根据我选择的选项卡,它应该只显示满足条件的项目。就像其他人建议的那样,我已经更改了该项目的不同名称,但它似乎仍然对我不起作用。

非常感谢任何帮助。

ui <- fluidPage(

  sidebarLayout(

    sidebarPanel(

      conditionalPanel(
        condition="input.tabselected=='AAA'",
        selectInput("selectDisease1", 
                   label="Select Disease:", 
                   choices=c("Disease 1","Disease 2") 
                   ),

        selectInput("selectProduct1", 
                   label="Select Products:", 
                   choices=product.list, 
                   selected=NULL, 
                   multiple=TRUE
                   ),

        selectInput("selectStartDate1", 
                   label="Select Start Date:", 
                   choices=names(SBI[c(5:num.columns)]), 
                   selected = 1
                   ), 

        selectInput("selectEndDate1", 
                   label="Select End Date:", 
                   names(SBI[c(5:num.columns)]), 
                   selected = 1
                   ),

        submitButton("Submit")

      ),

      conditionalPanel(
        condition="input.tabs=='Data'",
        selectInput("selectDisease2", 
                    label="Select Disease:", 
                    choices=c("Disease 1","Disease 2")  
        ),

        selectInput("selectProduct2", 
                    label="Select Products:", 
                    choices=product.list, 
                    selected=NULL, 
                    multiple=TRUE
        ),

        selectInput("selectStartDate2", 
                    label="Select Start Date:", 
                    choices=names(SBI[c(5:num.columns)]), 
                    selected = 1
        ), 

        selectInput("selectEndDate2", 
                    label="Select End Date:", 
                    names(SBI[c(5:num.columns)]), 
                    selected = 1
        ),

        numericInput("lines2", 
                     label="Number of Lines:", 
                     value=1
        ),

        dateRangeInput('dateRange2',
                       label = paste('Date range input 1:'),
                       separator = " - ", 
                       format = "yyyy-mm",
                       startview = 'month'
        ),

        submitButton("Submit")

      ),

      conditionalPanel(
        condition="input.tabs=='Plot'",
        selectInput("selectDisease3", 
                    label="Select Disease Stage:", 
                    choices=c("Disease Stage 1","Disease Stage 2")  
                    ),

        selectInput("selectProduct3", 
                    label="Select Products:", 
                    choices=product.list, 
                    selected=NULL, 
                    multiple=TRUE
                    ),

        selectInput("selectStartDate3", 
                    label="Select Start Date:", 
                    choices=names(SBI[c(5:num.columns)]), 
                    selected = 1
                    ), 

        selectInput("selectEndDate3", 
                    label="Select End Date:", 
                    names(SBI[c(5:num.columns)]), 
                    selected = 1
                    ),

        numericInput("trends3", 
                     label="Number of Linear Trends:", 
                     value=1
                    ),

        dateRangeInput('dateRange3',
                       label = paste('Date range input 1:'),
                       separator = " - ", 
                       format = "yyyy-mm",
                       startview = 'month'
                      ),
       dateRangeInput('dateRange4',
                       label = paste('Date range input 2:'),
                       separator = " - ", 
                       format = "yyyy-mm",
                       startview = 'month'
                      ),

        submitButton("Submit")

      )      
    ), 

    mainPanel(
      titlePanel("Assessment"),

      tabsetPanel(

        id = "tabselected",
        selected = NULL, 

        tabPanel("AAA Disease State", 
                 value="AAA", 
                 tags$hr(),
                 DT::dataTableOutput("sbirx.view", width = 300)
                 ),
        tabPanel("Data",
                 value="Data",
                 tags$hr(),
                 DT::dataTableOutput("sbirx.view", width = 300)
                ),
        tabPanel("Plot",
                 value="Plot",
                 tags$hr(),
                 DT::dataTableOutput("sbirx.view", width = 300)
                 )

      )

    ) # end of main panel

  ) # end of sidebarLayout

) # end of fluidpage

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    问题在于您对数据表的渲染,输出应该是唯一的。您只能渲染一次sbirx.view,如果您想显示输出 3 次,则分配类似 sbirx.view2sbirx.view3 的内容然后渲染它。同时删除submitButton 并按照@GGamba 的建议将actionButton 分配给每个人

    tabsetPanel(
    
    id = "tabselected",
    
    tabPanel("AAA Disease State", 
             value=10, 
             tags$hr()
             #,DT::dataTableOutput("sbirx.view", width = 300)
    ),
    tabPanel("Data",
             value=20,
             tags$hr()
            #,DT::dataTableOutput("sbirx.view", width = 300)
    ),
    tabPanel("Plot",
             value=30,
             tags$hr()
             #,DT::dataTableOutput("sbirx.view", width = 300)
    )
    

    )

    【讨论】:

    • @aotearoa 如果这是解决方案,请接受答案
    • 是的,我接受这个答案,因为这是我的问题的解决方案。感谢您花时间调查此事。祝你有美好的一天!
    • @aotearoa 请点击投票窗口旁边的绿色框。 stackoverflow.com/help/someone-answers
    【解决方案2】:

    如果面板内有submitButton(),则conditionalPanel 不起作用(可能是有意为之)。

    要修复它,请使用actionButton()

    请注意,您必须适当地更改服务器代码。

    【讨论】:

    • 感谢您的回复 GGamba。但是我尝试使用 actionButton()。它仍然是同样的问题。我尝试在没有任何 SubmitButton() 或 actionButton() 的情况下运行。还是一样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 2017-11-30
    • 2015-11-10
    • 1970-01-01
    • 2021-04-06
    • 2016-04-10
    相关资源
    最近更新 更多