当数字变更后调用另一个RenderPlot时,如何停止RenderPlot运行?
当我通过连续单击“快速”按钮来更改numericInput
值时,我的闪亮应用程序的过渡非常长。
一旦新的numericInput
已更改,如何停止以前的代码运行?我不知道我是否清楚地解释了我的问题。是否可以将GIF放入Stackoverflow帖子中?
# USER INTERFACE
ui <- fluidPage(
sidebarLayout(
sidebarPanel(numericInput("sd", p("sd"), value = 0.1, step = 0.1)),
mainPanel(plotOutput("plot"))
)
)
# SERVER
server <- function(input, output) {
output$plot<- renderPlot({
x <- seq(-1, 1, length.out = 50000)
plot(x, x + rnorm(50000, sd = input$sd), ylab = "y")
})
}
shinyApp(ui = ui, server = server)
The transitions of my Shiny app are very long when I change a numericInput
value by clicking on the button "quickly" several times in a row .
How can I stop the previous code from running once a new numericInput
has changed ? I don't know if I explained my problem clearly. Is it possible to put a GIF in a StackOverflow post ?
Try to play with the button to understand my problem
# USER INTERFACE
ui <- fluidPage(
sidebarLayout(
sidebarPanel(numericInput("sd", p("sd"), value = 0.1, step = 0.1)),
mainPanel(plotOutput("plot"))
)
)
# SERVER
server <- function(input, output) {
output$plot<- renderPlot({
x <- seq(-1, 1, length.out = 50000)
plot(x, x + rnorm(50000, sd = input$sd), ylab = "y")
})
}
shinyApp(ui = ui, server = server)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在不设置某种形式的情况下启动计算后取消计算
子过程处理。但是,即使在这种情况下,这也无济于事,
因为耗时的操作是实际的图形渲染。你会
需要一个自定义等效于
renderplot()
来处理它。您可以在这里做的最好的是
debounce()
输入,以便您直到输入值已经在一段时间内解决了一段时间之前,才会开始绘制:
或者,即使更改输入太快仍然是一个问题,即使拒绝,接受并使用提交按钮明确触发绘图。
You can’t cancel a computation once it’s started without setting up some sort
of subprocess processing. However, even that would not help in this case,
because the time-consuming operation is the actual graphics rendering. You’d
need a custom equivalent to
renderPlot()
to handle that.Likely the best you can do here is to
debounce()
the input, so that youwon’t start plotting until the input value has settled for some amount of time:
Or if changing inputs too quickly is still a problem even when debounced, accept that and use a submit button to explicitly trigger the plotting.