【发布时间】:2019-06-12 13:13:46
【问题描述】:
我有一个脚本要添加到我的 Shiny 应用程序中,原始脚本可以简化为以下内容:
plot(c(1:3),c(2,4,6), main ="This is first plot I want displayed")
a <- menu(c(1:5), title="what would you like to change the first point to?")
plot(c(1:3),c(a,4,6), main ="This is second plot I want displayed")
b <- menu(c(1:5), title="what would you like to change the second point to?")
plot(c(1:3),c(a,b,6), main ="This is second plot I want displayed")
上面的脚本绘制了第一个图,然后在绘制第二个之前等待用户输入,并在绘制第三个之前再次等待用户输入。
但是,当我尝试将其转换为如下所示的闪亮应用程序时,它永远不会更新第一个或第二个图,并且我试图让它停止以供用户输入显示的东西没有奏效。
我尝试过使用 req() 但它似乎完全停止了脚本,所以最后的事情根本没有运行,你必须重新启动整个脚本。
那么,我怎样才能让它按顺序显示所有的情节,我怎样才能让脚本在继续之前停止并等待输入?
if(interactive()){
ui <- fluidPage(
actionButton("button","Click me"),
selectInput("input", "Input", c(1:10)),
textOutput("text"),
plotOutput("plot")
)
server <- function(input, output) {
a<-1
observeEvent(input$button, {
output$plot <- renderPlot(plot(c(1:3),c(2,4,6), main ="This is first plot I want displayed"))
output$text <- renderText("Please select a number to multiply the first point with")
#This is where I want the script to wait for user input
output$plot <- renderPlot(plot(c((1),(2),(3)),c((input$input),(a),(3)), main="This is plot the second plot"))
a<-a+1
#Here I want the script to wait for user input again
output$plot <- renderPlot(plot(c((1),(2),(3)),c((input$input),(a),(3)), main="This is plot the third plot"))
})
}
shinyApp(ui=ui, server=server)
}
目标是当它们在代码中呈现时更新绘图,并等待用户输入直到脚本继续,而不是继续执行。
【问题讨论】:
-
我想澄清一下