2

In R, there are solutions to stop the App when the user closes the browser, such as

# in server.R
session$onSessionEnded(function() { stopApp() })

Is there some similar solution for python ?

I found this proposed solution, but it doesn't seem to work:

# In server: this closes the session when the user exits out on their browser
@reactive.Effect
@reactive.event(input.close)
async def _():
    await session.close()
M--
  • 25,431
  • 8
  • 61
  • 93
user2551579
  • 21
  • 1
  • 2

1 Answers1

0

I had the same need for my shiny app, just tried it with the docs and it worked:

I created an UI button to close the app :

ui.input_action_button(id="exit", label="Close App")

After that in the server I use

@reactive.Effect
@reactive.event(input.exit)
async def _():
     await session.close()

Make sure you dont import session from shiny so the object dont get confused

abe_mercy
  • 36
  • 2