重新启动闪亮的会话

汉密尔顿·布莱克

这似乎是一个非常明显的问题,但我还没有找到任何关于此的东西。

如何刷新闪亮的应用程序(相当于按F5或单击RStudio中的“重新加载应用程序”按钮)?

用户界面

 shinyUI(pageWithSidebar(
  headerPanel("Example"),
  sidebarPanel(
    actionButton("goButton", "Refresh")
  ),  
  mainPanel(
        h4("I would really like to refresh this please.")
    )   
))

服务器

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网站上,此处显示如何从服务器管理用户的会话。特别,

$ sudo rstudio-server suspend-session <pid>

在应用程序中是否具有与用户等效的功能?在会话信息的文档(此处)中,它说有一个onSessionEnded(callback)函数。如果有一个执行上述suspend-session功能的session.End()函数会很好!

泡沫

您可以使用history.go(0)js方法重新加载页面,从而重置会话,例如通过链接:

p(HTML("<A HREF=\"javascript:history.go(0)\">Reset this page</A>"))

此外,您可以使用该shinyjs从服务器内部执行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
  })

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章