需要一种无需完成 Shiny 中的代码序列即可立即重新加载会话的方法
Need a way to reload the session immediately without finishing the code sequence in Shiny
我正在使用 shiny 包来构建工具的 Web 版本。在提供输出之前必须对用户输入执行验证。其中一项验证需要刷新工具。
为此,我尝试在名为 "Display results" 的操作按钮中使用 "session$reload"。
虽然 session$reload 在响应式按钮中工作得很好,但我需要一种方法来重置会话而不完成代码序列。
工作会话重新加载
server <- function(input, output, session) {
{ #Test Door Identification Server
#Refresh button
observeEvent(input$refresh, {
session$reload()
})
session$code 需要立即重置的一段代码
library(shiny)
ui <- fluidPage(
actionButton('switchtab',"Click this"),
textOutput('code_ran')
)
server <- function(input, output, session){
observeEvent(input$switchtab,{
aggg_result = -1
if(aggg_result == -1)
{
session$reload()
print("session reload not working")
}
print("Code running this line")
output$code_ran <- renderText("code Ran this line without refreshing")
})
}
shinyApp(ui = ui, server = server)
这个函数的输出:
打印 "reload doesnt work" 并继续执行其余语句。
我知道这就是 session$reload 的工作原理,但是有没有办法在不打印的情况下重置 "Code running this line"?
任何 directions/suggestions 都将受到欢迎。
此致,
维维克 S
好的,在 session$reload()
之后简单地做一个 return()
怎么样?
library(shiny)
ui <- fluidPage(
actionButton('switchtab',"Click this"),
textOutput('code_ran')
)
server <- function(input, output, session){
print("Initializing")
observeEvent(input$switchtab,{
aggg_result = -1
if(aggg_result == -1)
{
session$reload()
return()
print("session reload not working")
}
print("Code running this line")
output$code_ran <- renderText("code Ran this line without refreshing")
})
}
shinyApp(ui = ui, server = server)
它实现了你想要的,对吧?
我正在使用 shiny 包来构建工具的 Web 版本。在提供输出之前必须对用户输入执行验证。其中一项验证需要刷新工具。
为此,我尝试在名为 "Display results" 的操作按钮中使用 "session$reload"。
虽然 session$reload 在响应式按钮中工作得很好,但我需要一种方法来重置会话而不完成代码序列。
工作会话重新加载
server <- function(input, output, session) {
{ #Test Door Identification Server
#Refresh button
observeEvent(input$refresh, {
session$reload()
})
session$code 需要立即重置的一段代码
library(shiny)
ui <- fluidPage(
actionButton('switchtab',"Click this"),
textOutput('code_ran')
)
server <- function(input, output, session){
observeEvent(input$switchtab,{
aggg_result = -1
if(aggg_result == -1)
{
session$reload()
print("session reload not working")
}
print("Code running this line")
output$code_ran <- renderText("code Ran this line without refreshing")
})
}
shinyApp(ui = ui, server = server)
这个函数的输出: 打印 "reload doesnt work" 并继续执行其余语句。
我知道这就是 session$reload 的工作原理,但是有没有办法在不打印的情况下重置 "Code running this line"?
任何 directions/suggestions 都将受到欢迎。
此致, 维维克 S
好的,在 session$reload()
之后简单地做一个 return()
怎么样?
library(shiny)
ui <- fluidPage(
actionButton('switchtab',"Click this"),
textOutput('code_ran')
)
server <- function(input, output, session){
print("Initializing")
observeEvent(input$switchtab,{
aggg_result = -1
if(aggg_result == -1)
{
session$reload()
return()
print("session reload not working")
}
print("Code running this line")
output$code_ran <- renderText("code Ran this line without refreshing")
})
}
shinyApp(ui = ui, server = server)
它实现了你想要的,对吧?