这似乎是一个非常明显的问题,但我还没有找到关于这个主题的任何内容.
如何刷新闪亮的应用程序(相当于按下F5,或单击RStudio中的"重新加载应用程序"按钮)?
ui.R
shinyUI(pageWithSidebar(
headerPanel("Example"),
sidebarPanel(
actionButton("goButton", "Refresh")
),
mainPanel(
h4("I would really like to refresh this please.")
)
))
Run Code Online (Sandbox Code Playgroud)
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)...
})
})
})
Run Code Online (Sandbox Code Playgroud)
我不认为我想使用stopApp() - 我只想刷新它,使其处于加载时的状态.
UPDATE
在RStudio网站上,它显示了如何从服务器管理用户的会话.特别,
$ sudo rstudio-server suspend-session <pid>
Run Code Online (Sandbox Code Playgroud)
应用程序中是否存在与用户相同的功能?在会话信息的文档中(这里),它说有一个onSessionEnded(回调)函数.如果有session.End()函数执行上面的suspend-session函数会很好!
Jan*_*Jan 14
会话现在有一个方法来解决这个问题。不再需要 Shinyjs:
session$reload()
Run Code Online (Sandbox Code Playgroud)
bub*_*ble 11
您可以使用history.go(0)
js-method重新加载页面,从而重置会话,例如从链接:
p(HTML("<A HREF=\"javascript:history.go(0)\">Reset this page</A>"))
Run Code Online (Sandbox Code Playgroud)
此外,您可以使用该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
})
Run Code Online (Sandbox Code Playgroud)
您可以通过在您的 ui 代码中包含以下内容,为您的应用添加刷新图标和弹出框:
library(shinyBS)
tags$a(href="javascript:history.go(0)",
popify(tags$i(class="fa fa-refresh fa-5x"),
title = "Reload",
content = "Click here to restart the Shiny session",
placement = "right"))
Run Code Online (Sandbox Code Playgroud)
它应该给你这个:
归档时间: |
|
查看次数: |
8628 次 |
最近记录: |