File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,10 @@ def generate_report(
7878 report_manag_content .append (
7979 textwrap .dedent (
8080 """\
81+ import os
82+ import time
83+
84+ import psutil
8185 import streamlit as st
8286 """
8387 )
@@ -155,8 +159,24 @@ def generate_report(
155159
156160 # Add navigation object to the home page content
157161 report_manag_content .append (
158- f"""report_nav = st.navigation(sections_pages)
159- report_nav.run()"""
162+ textwrap .dedent (
163+ """\
164+ report_nav = st.navigation(sections_pages)
165+
166+ # Following https://discuss.streamlit.io/t/close-streamlit-app-with-button-click/35132/5
167+ exit_app = st.sidebar.button("Shut Down App")
168+ if exit_app:
169+ st.toast("Shutting down the app...")
170+ time.sleep(1)
171+ # Terminate streamlit python process
172+ pid = os.getpid()
173+ p = psutil.Process(pid)
174+ p.terminate()
175+
176+
177+ report_nav.run()
178+ """
179+ )
160180 )
161181
162182 # Write the navigation and general content to a Python file
You can’t perform that action at this time.
0 commit comments