2014-03-04 21 views
0

我想爲我的UI生成一些輸入取決於actionButton的值。生成textInputs工作正常(請參閱下面的可重複代碼),但生成actionButtons似乎很棘手。R閃亮:如何生成actionButtons依次取決於另一個主要actionButton

下面是代碼:

shiny::runApp(
list(
ui = pageWithSidebar(
headerPanel("test"), 
sidebarPanel(
actionButton("create","create") 
),  
mainPanel( 
uiOutput('the_textInputs'), 
uiOutput('the_buttons') 
)) 
, 
server = function(input,output){ 
observe({ 
if (input$create == 0) 
return() 
isolate({ 

output$the_textInputs <- renderText({ #this works nicely 
A <- paste0("<input id='A", 1:input$create, "' class='shiny-bound-input' type='text' value=''>") 
}) 

output$the_buttons <- renderUI({ # this does not work properly, probably due to the html commands here below not well specified 
B <- paste0("<input id='B", 1:input$create, "' class='btn action-button' type='button' >") 
}) 

}) 
}) 

} 
)) 

任何建議或意見,將不勝感激!

乾杯

回答

2

renderUI,你只能用「返回一個閃亮的標籤對象,HTML,或此類對象的列表的表達。」

您必須更改output$the_buttons <- renderTextrenderUI功能將您的字符串轉換爲HTML:B <- HTML(paste0("<input id='B", 1:input$create, "' class='btn action-button' type='button' >"))

+0

非常感謝!它確實有效!只是一個額外的問題(抱歉exagerate):我如何指定標籤? B < - HTML(paste0(「「) ) – user1431694

+0

它不是'label',而是'value'。 http://www.w3schools.com/tags/tag_input.asp –