在点击
Inputs
后,我尝试在 Shiny 应用程序中生成一些新的 actionButton
,但我可以看到我做错了什么。
histogramUI <- function(id) {
tagList(
actionButton(NS(id, "generate_pickers"), "Generate pickers"),
renderUI(NS(id, "new_button"))
)
}
histogramServer <- function(id) {
moduleServer(id, function(input, output, session) {
observeEvent(input$generate_pickers, {
new_button <- pickerInput(NS(id, "new_button"), "New Button", choices = c())
output$new_button <- renderUI(tagList(new_button))
})
})
}
histogramApp <- function() {
ui <- fluidPage(
histogramUI("hist1")
)
server <- function(input, output, session) {
histogramServer("hist1")
}
shinyApp(ui, server)
}
histogramApp()
在 UI 中您需要使用
uiOutput
而不是 renderUI
uiOutput(NS(id, "new_button"))
完整代码:
library(shiny)
library(shinyWidgets)
histogramUI <- function(id) {
tagList(
actionButton(NS(id, "generate_pickers"), "Generate pickers"),
uiOutput(NS(id, "new_button"))
)
}
histogramServer <- function(id) {
moduleServer(id, function(input, output, session) {
observeEvent(input$generate_pickers, {
new_button <- pickerInput(NS(id, "new_button"), "New Button", choices = c())
output$new_button <- renderUI(tagList(new_button))
})
})
}
histogramApp <- function() {
ui <- fluidPage(
histogramUI("hist1")
)
server <- function(input, output, session) {
histogramServer("hist1")
}
shinyApp(ui, server)
}
histogramApp()