2017-04-03 72 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