2014-02-20 37 views
4

我需要在我的界面中有多個選項卡,並且在每個選項卡中我想使用conditionalPanel。正如您將在下面看到的可重複代碼,conditionalPanel在第一個選項卡中工作,但不在其他選項卡中。R Shiny:如果在不同的標籤中使用條件面板不工作

ui <- pageWithSidebar(
headerPanel("Hello !"), 
sidebarPanel(
tabsetPanel(
tabPanel("a", 
textInput(inputId = "A1", label = "1:", value = "A1"),    
checkboxInput(inputId = "new_A2", 
label = "Add another one", 
value = FALSE), 

conditionalPanel(
condition = "input.new_A2 == true", 
textInput(inputId = "A2", label = "2:", value = "A2") 
)), 
tabPanel("b", 
textInput(inputId = "B1", label = "1:", value = "C1"), 
checkboxInput(inputId = "new_B2", 
label = "Add another one", 
value = FALSE), 

conditionalPanel(
condition = "input.new_B2 == true", 

textInput(inputId = "B2", label = "2:", value = "C2")  
) 
) 
) 
), 

mainPanel() 
) 

server <- function(input,output){ 
} 

runApp(list(ui=ui,server=server)) 

我知道有很多與conditionalPanel有關的問題,但我還沒有找到答案。

謝謝你在前進,任何建議高度讚賞

回答

6

給你的標籤集面板的ID例如tabsetPanel(id="tabs"並添加條件時,標籤「B」的重點是input.tabs == 'b'

例如,在你的第二個條件面板條件將是:

condition = "input.tabs == 'b' & input.new_B2 == true"

+0

非常感謝Julien!它適用於這種情況。 – user1431694

+0

它不適用於閃亮版本0.12.2.9007。如何檢查屬於輸入的項目?如輸入$標籤閃亮?謝謝。 –

+0

它似乎在新版本中。 'input.tabs =='b'&'應該被刪除,這意味着原作品。 –