这似乎是一个非常明显的问题,但我还没有找到关于这个主题的任何内容。
如何刷新闪亮的应用程序(相当于按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()函数执行上面的suspend-session函数会很好!
答案 0 :(得分:9)
您可以使用history.go(0)
js-method重新加载页面,从而重置会话,例如来自一个链接:
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), # 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
})
答案 1 :(得分:6)
会话现在有一种方法可以解决问题。不再需要Shinyjs:
session$reload()
答案 2 :(得分:4)