我尝试将一个actionButton与watchEvent一起使用。我的问题是:我可以通过单击按钮来定义不同的动作吗?像
`observeEvent(input$verlauf,{
if (input$verlauf == 0){input$verlauf <- 1 & renderTable(BDI2())}
else if (input$verlauf == 1){input$verlauf <- 2 & renderTable(BDI2())}
else if (input$verlauf == 2){input$verlauf <- 3 & renderTable(BDI3())}
else if (input$verlauf == 3){input$verlauf <- 4 & renderTable(BDI4())}
else if (input$verlauf == 4){input$verlauf <- 5 & renderTable(BDI5())}
else if (input$verlauf == 5){input$verlauf <- 6 & renderTable(BDI6())}
else {}})`
每次单击actionButton时,应该有一个不同的动作。如何在我的R /闪亮代码中执行此操作?它不会工作
非常感谢:)
derlu
答案 0 :(得分:1)
您不能递增input$verlauf
的值,但是可以创建一个reactiveValues
对象并递增该值。参见下面的示例。
library(shiny)
shinyApp(
ui = fluidPage(
actionButton(inputId = "button",
label = "I am a Button. Click me!"),
uiOutput("result")
),
server = shinyServer(function(input, output, session){
# MAKE A REACTIVE VALUES OBJECT HERE. THIS BEHAVES LIKE A LIST, BUT
# CAN TRIGGER REACTIVE COMPONENTS
Button <- reactiveValues(
Click = 0
)
# Update the Button$Click object on each click of input$button
observeEvent(input$button,
{
Button$Click <- input$button %% 8
})
# Take an element of the vector. This is changed every time
# Button$Click changes.
output$result <-
renderUI({
p(c("It's raining tacos.",
"From out of the sky.",
"Tacos.",
"No need to ask why.",
"Just open your mouth",
"and close your eyes...",
"it's raining tacos.")[Button$Click])
})
})
)