【发布时间】:2021-10-04 22:32:18
【问题描述】:
为什么observeEvent() 在我使用tags$button 和相应的id 时没有被触发,但是当我使用actionButton 和inputId 时。区别在哪里?如何使我的自定义 html tags$button 成为实际的“事件”?
这不起作用:
library(shiny)
if (interactive()) {
options(device.ask.default = FALSE)
ui = fluidPage(
tags$button(id = "action", "BTN"),
plotOutput(outputId = "plot"))
server = function(input, output, session){
observeEvent(input$action, {
output$plot = renderPlot({
hist(iris$Sepal.Length)})
})
}
shinyApp(ui, server)
}
这样做:
library(shiny)
if (interactive()) {
options(device.ask.default = FALSE)
ui = fluidPage(
actionButton(inputId = "action", label = "BTN"),
plotOutput(outputId = "plot"))
server = function(input, output, session){
observeEvent(input$action, {
output$plot = renderPlot({
hist(iris$Sepal.Length)})
})
}
shinyApp(ui, server)
}
【问题讨论】:
标签: r shiny shiny-reactivity