0

i try to use an actionButton with observeEvent. My question is: can i define different actions with a second click on the button? something like

`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 {}})`

on every click on the actionButton there should be a different action. How can i do this in my R / shiny code? it wont work

Thank you very much :)

derlu

1 Answer 1

1

You can't increment the value of input$verlauf, but you can make a reactiveValues object and increment that value. See below for an example.

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])
      })
  })
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.