Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 更新-动态更改绘图数据行_R_Shiny_Reactive Programming - Fatal编程技术网

R 更新-动态更改绘图数据行

R 更新-动态更改绘图数据行,r,shiny,reactive-programming,R,Shiny,Reactive Programming,我知道renderPlot生成的绘图可以显示在闪亮的plotOutput函数上。我还知道autoinvalidate()有助于反应性地计算数据 我使用以下代码显示雷达图(实际上可以是任何图表): output$plot2 <- renderPlot({ autoInvalidate() p2<<-ggradar(mtcars_radar[i,]) }) 输出$plot2% 尾部(4)%>%选择(1:10)->mtcars\U雷达 ui在这里

我知道renderPlot生成的绘图可以显示在闪亮的plotOutput函数上。我还知道autoinvalidate()有助于反应性地计算数据

我使用以下代码显示雷达图(实际上可以是任何图表):

output$plot2 <- renderPlot({
      autoInvalidate()
        p2<<-ggradar(mtcars_radar[i,])
    })
输出$plot2%
尾部(4)%>%选择(1:10)->mtcars\U雷达

ui在这里,您需要一个被动值来存储行索引并每秒更改。我没有库
ggradar
,因此我将只打印当前行索引值。我还使用了
invalidaterater
,而不是所建议的
reactiveTimer

库(闪亮)

其他地方有一些建议告诉我们如何使用动画滑块输入。但这种方法很慢。你的建议太棒了。谢谢你救了我。请回答一个额外的问题,如何在一定次数的迭代后停止失效?@doctshinds我更新了代码,添加了一个条件测试
invalidateLater
什么都不做,只是制定了一个“稍后运行此反应性块”的计划,了解它的作用将帮助您更好地理解为什么这样做。您需要注意的一点是,如果使用
row_idx()
对数据进行子集设置,请检查它是否大于0,因为我相信在它立即递增为1之前,有一小段时间它是0。非常感谢。很好的方法,非常感谢分享您的知识
library(shiny)
library(ggplot2)
 mtcars %>%
 rownames_to_column( var = "group" ) %>%
 mutate_at(vars(-group),funs(rescale)) %>%
 tail(4) %>% select(1:10) -> mtcars_radar

ui <- fluidPage(
  sidebarPanel(

    actionButton("button", "Go!")
  ),
  # Show the plot
  mainPanel(
    plotOutput("plot2")
  )
)

server <- function(input, output) {
  library(ggplot2)
  library(ggradar)
  suppressPackageStartupMessages(library(dplyr))
  library(scales)

  autoInvalidate <- reactiveTimer(2000)
  plot2 <- NULL


  output$plot2 <- renderPlot({
    ggradar(mtcars_radar[1,])
  })
  observeEvent(input$button,{

     output$plot2 <- renderPlot({
      autoInvalidate()
        p2<<-ggradar(mtcars_radar[i,])
        p2
    })
  })

}

# Run the application 
shinyApp(ui = ui, server = server)
library(shiny)

ui <- fluidPage(
  verbatimTextOutput("debug")
)

server <- function(input, output) {

  row_idx_max <- 15
  row_idx <- reactiveVal(0)

  observe({
    isolate(row_idx(row_idx() + 1))
    cur_row_idx <- isolate(row_idx())
    if (cur_row_idx < row_idx_max) {
      invalidateLater(1000)
    }
  })

  output$debug <- renderPrint({
    row_idx()
  })
}

shinyApp(ui, server)