我正在构建一个包含多个选项卡的应用程序,其中一些涉及过多的计算,另一些涉及快速计算.允许用户在反应性或手动更新之间进行选择的复选框与"刷新"按钮相结合将是理想的.
下面的简单示例说明了我的目标.它几乎可以工作,除了在"自动刷新" - 检查框未选中时最后一次刷新,这是一个痛苦,如果计算密集的选项卡打开.有没有办法解决?
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"))
)
)
)
))
Run Code Online (Sandbox Code Playgroud)
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)
})
})
})
Run Code Online (Sandbox Code Playgroud)
提前谢谢了!