借助handsontable进行闪亮的延迟计算

时间:2018-07-24 12:47:00

标签: r shiny handsontable rhandsontable

在下面的MRE中,要求用户填写绘制曲线的表格。为了模拟在生成图形输出之前在表上进行的计算,我添加了Sys.sleep()。您将看到,如果表的填充速度足够快(即比Sys.sleep()快),则该应用程序将变得无法使用并且必须被杀死。

我相信这是因为表渲染是在计算/休眠和绘图渲染之后发生的。我应该如何解决此问题,以使应用程序实时做出反应并仍然可用?

library(shiny)
library(rhandsontable)
library(ggplot2)

DF <- data.frame(x=integer(0), y=integer(0))

ui <- shinyUI(fluidPage(

  mainPanel( 
    rHandsontableOutput("hot"),
    plotOutput("plot1")
  )
))


server <- shinyServer(function(input, output) {

  values <- reactiveValues()

  observe({
    if (!is.null(input$hot)) {
      DF <- hot_to_r(input$hot)
    } else {
      if (is.null(values[["DF"]]))
        DF <- DF
      else
        DF <- values[["DF"]]
    }
    values[["DF"]] <- DF
  })

  output$hot <- renderRHandsontable({
    rhandsontable(values[["DF"]], stretchH = "all", minRows=5)
  })

  output$plot1 <- renderPlot({

      table <- {
        Sys.sleep(.4)
        values[["DF"]]
        }

      ggplot(data=table) + geom_line(aes(x=x, y=y))

  })

})

shinyApp(ui=ui, server=server)

0 个答案:

没有答案