闪亮的颜色中的eventReactive';更新数据

闪亮的颜色中的eventReactive';更新数据,r,rstudio,shiny,R,Rstudio,Shiny,在我下面的示例中,一旦在RStudio中运行,通过单击滑块上的“播放”按钮,移动的行数将逐渐增加。但是通过暂停,然后将数据集名称更改为iris,然后单击按钮“显示”并重新单击“播放”,行数不会出现相同的动画增加…为什么?我如何调整我的代码来做到这一点。让动画以不同的数据集出现 下面的示例部分改编自eventReactive()函数 require(shiny) if (interactive()) { ui <- fluidPage( column(4,

在我下面的示例中,一旦在RStudio中运行,通过单击滑块上的“播放”按钮,移动的行数将逐渐增加。但是通过暂停,然后将数据集名称更改为
iris
,然后单击按钮“显示”并重新单击“播放”,行数不会出现相同的动画增加…为什么?我如何调整我的代码来做到这一点。让动画以不同的数据集出现

下面的示例部分改编自
eventReactive()
函数

require(shiny)
if (interactive()) {
  ui <- fluidPage(
    column(4,
           sliderInput('x',label='Num Rows',min=2,max=30,step=1,value=3,animate = TRUE),
           textInput('tbl_nm',label='Data Set',value='cars'),
           br(),
           actionButton("button", "Show")
     ),
     column(8, tableOutput("table"))
   )
   server <- function(input, output) {

    # reactively adjust the number of rows
    ll <- eventReactive(input$x,{
      input$x
    })


    # change the data sets after clicking the button
    dat <- eventReactive(input$button,{
       if(input$tbl_nm=='cars'){
         dat <- cars
      } else {
         dat <- get(input$tbl_nm)
      }
      return(dat)
     })

    # Take a reactive dependency on input$button, but
    # not on any of the stuff inside the function
    df <- eventReactive(input$button, {
       yy <- ll()
      # choose only the relevant data...
      head(dat(),yy)
    })

    # show the final table
    output$table <- renderTable({

      if(input$button==0){
        # show the first few lines of cars at the begining
        head(cars, ll())
      } else {
        # show the selected data
        df()
      }

    })
  }


  shinyApp(ui=ui, server=server)
}
require(闪亮)
if(interactive()){

ui发生这种情况的原因是:

output$table <- renderTable({

  if(input$button==0){
    # show the first few lines of cars at the begining
    head(cars, ll())
  } else {
    # show the selected data
    df()
  }

})

作为您的
df()
。如果按下按钮或滑块更新,它现在将更新。发生这种情况的原因是:

output$table <- renderTable({

  if(input$button==0){
    # show the first few lines of cars at the begining
    head(cars, ll())
  } else {
    # show the selected data
    df()
  }

})
改为您的
df()
。如果按下按钮或滑块更新,它现在将更新