【发布时间】:2019-01-02 07:57:12
【问题描述】:
考虑到用户手动填写rhandsontable,我想实现一个与时间相关的条件来进行表格分析和绘图。 例如如果在最后 2 秒内没有向表中添加任何内容,则继续,否则等待 2 秒过去。
我尝试使用validate() 或简单条件(如下所示)。它不起作用,因为observe()是在表修改后立即访问的,当时与时间相关的条件是false。当条件应为true 时,将不再访问observe() 函数,因此不测试条件...
我试图提供一个 MRE,但在一个简单的示例中我无法证明对此类功能的需求。需求与分析和绘图的计算时间有关。
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()
values$table <- DF
values$accessDF <- 0
observe({
if (!is.null(input$hot)) {
DF <- hot_to_r(input$hot)
values$accessDF <- Sys.time() # reset awaiting time when table is incremented
} 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)
})
observe({
if (Sys.time() - values$accessDF > 2){ # unfornate try...
# some modification of the table occuring here
values$table <- values$DF
}
})
output$plot1 <- renderPlot({
ggplot(data=values$table) + geom_line(aes(x=x, y=y))
})
})
shinyApp(ui=ui, server=server)
【问题讨论】:
标签: r shiny handsontable rhandsontable