【问题标题】:observe event different actions on 2nd & 3rd event观察第二个和第三个事件的不同动作
【发布时间】:2018-07-24 21:14:09
【问题描述】:

我尝试使用带有 observeEvent 的 actionButton。我的问题是:我可以通过第二次单击按钮来定义不同的操作吗?像

`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 / 闪亮代码中做到这一点?它不会工作

非常感谢:)

德鲁

【问题讨论】:

    标签: r shiny


    【解决方案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])
          })
      })
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      • 2018-06-16
      相关资源
      最近更新 更多