我想我缺少了一些简单的东西。
我希望用户单击操作按钮1,以便出现操作按钮2。但是如何在ui中“渲染”新的操作按钮?
我的代码如下。 非常感谢你!
library(shiny)
ui = shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("button1", label = "Press Button 1")
),
mainPanel(
# what should I write here?
#renderPrint("button2")
)
)
))
server = shinyServer(function(input, output, session) {
observeEvent(input$button1, {
output$button2 <- renderUI({
actionButton("button2", label = "Press Button 2")
})
})
})
shinyApp(ui = ui, server = server)
答案 0 :(得分:1)
如果在服务器端使用renderUI()
,则必须在ui端使用uiOutput()
。
完整代码如下:
library(shiny)
ui = shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("button1", label = "Press Button 1")
),
mainPanel(
# what should I write here?
uiOutput("button2")
)
)
))
server = shinyServer(function(input, output, session) {
observeEvent(input$button1, {
output$button2 <- renderUI({
actionButton("button2", label = "Press Button 2")
})
})
})
shinyApp(ui = ui, server = server)