Sto*_*ace 5 r shiny shiny-server
我有一个相当复杂的 Shiny 应用程序,但发生了一些奇怪的事情:当我打印出应用程序执行的一些中间步骤时,所有内容都打印了两次。这意味着,一切都会被评估等两次。
我知道没有看到节目很难说出问题的原因,但也许有人可以指出我(根据经验/知识)可能是什么问题。
就像我在评论中提到的,isolate() 应该可以解决你的问题。除了 Rstudio 文档之外http://shiny.rstudio.com/articles/reactivity-overview.html 我推荐以下博客文章,了解 RStudio 文档之外的有趣信息。 https://shinydata.wordpress.com/2015/02/02/a-few-things-i-learned-about-shiny-and-reactive-programming/
简而言之,处理触发的最简单方法是将代码包装在isolate()中,然后只写下变量/输入,这应该在隔离之前触发更改。
output$text <- renderText({
input$mytext # I trigger changes
isolate({ # No more dependencies from here on
# do stuff with input$mytext
# .....
finishedtext = input$mytext
return(finishedtext)
})
})
Run Code Online (Sandbox Code Playgroud)
可重现的例子:
library(shiny)
ui <- fluidPage(
textInput(inputId = "mytext", label = "I trigger changes", value = "Init"),
textInput(inputId = "mytext2", label = "I DONT trigger changes"),
textOutput("text")
)
server <- function(input, output, session) {
output$text <- renderText({
input$mytext # I trigger changes
isolate({ # No more dependencies from here on
input$mytext2
# do stuff with input$mytext
# .....
finishedtext = input$mytext
return(finishedtext)
})
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)