我正在构建一个包含多个选项卡的应用程序,其中一些涉及过多的计算和其他计算速度很快的应用程序。一个允许用户在反应性或手动更新之间进行选择的复选框,结合“刷新”按钮将是理想选择。闪亮:允许反应性是用户可选的
下面的简单例子说明了我的目标。它几乎可行,除非最后一次刷新时“自动刷新” - 复选框未被选中,这是一个痛苦,如果打开一个计算密集型选项卡。有没有办法解决?
ui.r
library(shiny)
shinyUI(fluidPage(
titlePanel("Test"),
sidebarLayout(
sidebarPanel(
checkboxInput("autoRefresh", "Automatically refresh", TRUE),
actionButton("refresh", "Refresh!"),
radioButtons("choice", "Choice of value:",
c("10" = 10,
"20" = 20))
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Add random decimals to value", textOutput("value"))
)
)
)
))
server.r
library(shiny)
shinyServer(function(input, output) {
output$value <- renderText({
input$refresh
if(input$autoRefresh == 1) {
input$choice
}
isolate({
output <- runif(1,0,1) + as.numeric(input$choice)
})
})
})
提前非常感谢!
错字:Refesh。 更重要的是,这不起作用。当箱子未被选中时它刷新。这是因为它不工作,你解释它的方式......“如果”语句,直到输入$选择的变化进入触发整个renderText()块的执行。 – hedgedandlevered
@hedgedandlevered谢谢!更新了答案。 –
此代码现在可用。 –