Need a way to immediately reload the session without ending the code sequence in Shiny

Using the shiny package to create a web version of the tool. It is imperative to perform validation on user inputs before submitting the output. One of the checks requires the tool to be updated.
To do this, I'm trying to use "session $ reload" inside an action button called "Show Results".
While reloading the $ session works fine in reactive buttons, I need a way to reset the session without ending the code sequence.

Reboot the work session

server <- function(input, output, session) {

        { #Test Door Identification Server

          #Refresh button
          observeEvent(input$refresh, {
            session$reload()
          })

      

code snippet that requires session code $ code reset

    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)

      

the output of this function is: Print "reboot does not work" and continues with the rest of the statements.

I understand this is how the $ session reload works, but is there a way to reset it without printing "Code running this line"?

Any guidance / suggestions would be most welcome.

Regards, Vevek S

+3


source to share


1 answer


Ok, how about just return()

after session$reload()

this?

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)

      



It does what you want it to do, right?

+1


source







All Articles