大家。我想在闪亮中使用两个actionButtons来控制项目的值。代码如下:
ui <- fluidPage(
actionButton(
inputId = "bt2",
label = "BT2",
styleclass = "info"
),
actionButton(
inputId = "bt1",
label = "BT1",
styleclass = "info"
),
textOutput(outputId = "test")
)
server <- function(input, output, session) {
test <- eventReactive(eventExpr = input$bt1, {
"1"
})
observeEvent(eventExpr = input$bt2, {
test <- reactive({"2"})
})
output$test <- renderText({
test()
})
}
shinyApp(ui = ui, server = server)
然而,它没有用! 有人可以帮帮我吗? 非常感谢你!!!
答案 0 :(得分:0)
我添加了reactiveValues
来帮助您,因为您想使用observeEvent
library(shiny)
ui <- fluidPage(
actionButton(
inputId = "bt2",
label = "BT2",
styleclass = "info"
),
actionButton(
inputId = "bt1",
label = "BT1",
styleclass = "info"
),
textOutput(outputId = "test")
)
server <- function(input, output, session) {
v <- reactiveValues()
observeEvent(input$bt1,{
v$test <- "1"
})
observeEvent(input$bt2, {
v$test <- "2"
})
output$test <- renderText({
v$test
})
}
shinyApp(ui = ui, server = server)