我试图根据actionButton的值为UI生成一些输入。生成textInputs很好(请参阅下面的可重复代码),但是生成actionButtons似乎很棘手。
以下是代码:
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' >")
})
})
})
}
))
如有任何建议或建议,将不胜感激!
干杯
发布于 2014-03-04 12:25:49
在renderUI
中,您只能使用“返回闪亮的标记对象、HTML或此类对象列表的表达式”。
必须更改output$the_buttons <- renderText
或renderUI
函数,将字符串转换为HTML:B <- HTML(paste0("<input id='B", 1:input$create, "' class='btn action-button' type='button' >"))
https://stackoverflow.com/questions/22171664
复制相似问题