2017-04-03 71 views
1

我是Shiny的新手,我有这个代码。我创建了3个tabPanels。当我运行Shiny App时 - 它显示了所有选项卡中的所有条件集。根据我选择的选项卡,它应该只显示符合条件的项目。我已经改变了项目的不同名称,就像其他人所建议的一样,但它似乎仍然不起作用。闪亮的条件面板显示所有标签上的所有条件

任何帮助都是非常感激的接力。

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 

回答

0

问题在于您对数据表的渲染,输出应该是唯一的。如果要显示输出3次,然后指定sbirx.view2sbirx.view3之类的字符,然后进行渲染,则只能渲染sbirx.view一次。同时删除了submitButton并分配actionButton每一个为@GGamba建议

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

+0

解决了这个问题。谢谢 – aotearoa

+0

@aotearoa如果这是解决方案,请接受答案 –

+0

是的,我接受答案,因为这是解决我的问题。感谢您花时间研究这一点。祝你有美好的一天! – aotearoa

0

有一个问题(也许它的预期),其中conditionalPanel如果在面板内submitButton()不起作用。

要修复它,请使用actionButton()

请注意,您将不得不适当地更改您的服务器代码。

+0

感谢您回应GGamba。不过,我尝试使用actionButton()。它仍然是同样的问题。我试着运行没有任何SubmitButton()或actionButton()。这仍然是同样的问题。 – aotearoa