Skip to content

Commit 1d6db07

Browse files
committed
1 parent 2aba1bc commit 1d6db07

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/vuegen/streamlit_reportview.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)