重新启动闪亮会话 [英] Restart Shiny Session
本文介绍了重新启动闪亮会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这似乎是一个非常明显的问题,但我在这个主题上没有发现任何东西。
如何刷新闪亮的应用程序(相当于按F5或单击RStudio中的"重新加载应用程序"按钮)?
ui.R
shinyUI(pageWithSidebar(
headerPanel("Example"),
sidebarPanel(
actionButton("goButton", "Refresh")
),
mainPanel(
h4("I would really like to refresh this please.")
)
))
server.R
shinyServer(function(input, output,session) {
observe({
if(input$goButton==0) return(NULL)
isolate({
#
# I would like to refresh my session here with some sort of
# function like session(refresh)...
})
})
})
我认为我不想使用stopApp()-我只想刷新它,使其处于与加载时相同的状态。
更新
在RStudio网站上,它显示here如何从服务器管理用户会话。具体地说,
$ sudo rstudio-server suspend-session <pid>
在应用程序中是否有与用户等同的功能?在会话信息文档(here)中,它说有一个onSessionEnded(回调)函数。如果有执行上述挂起会话功能的session.End()函数就好了!
推荐答案
您可以使用history.go(0)
js-方法重新加载页面,从而重置会话,例如从链接:
p(HTML("<A HREF="javascript:history.go(0)">Reset this page</A>"))
此外,您还可以使用shinyjs
package从服务器内部执行javascript:
library(shiny)
library(shinyjs)
jsResetCode <- "shinyjs.reset = function() {history.go(0)}" # Define the js method that resets the page
shinyApp(
ui = fluidPage(
useShinyjs(), # Include shinyjs in the UI
extendShinyjs(text = jsResetCode, functions = "reset"), # Add the js code to the page
actionButton("reset_button", "Reset Page")
),
server = function(input, output) {
observeEvent(input$reset_button, {js$reset()}) # Call the method from
# somewhere within the server
})
这篇关于重新启动闪亮会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文