i have a strreamlit @st.dialog window [code] produced html code [code] But whenever i…
- User
i have a strreamlit @st.dialog window
@st.dialog("Error", width="large") # Set modal to True def show_exception(exception): st.error(f"{type(exception).__name__}: {str(exception)}") traceback_button = st.button("Show Traceback") if traceback_button: trace = traceback.extract_tb(exception.__traceback__) trace_details = [] for frame in trace: trace_details.append( f'File "{frame.filename}", line {frame.lineno}, in {frame.name}\n {frame.line}' ) st.code("Traceback:\n" + "\n".join(trace_details), language=None)produced html code
<div tabindex="-1" aria-modal="true" aria-label="dialog" role="dialog" class="st-ct st-cu st-cv st-cw st-cx st-cy st-al st-cz st-am st-d0 st-c1 st-d1 st-f6 st-f7 st-d3 st-cr st-b5 st-d4 st-d5 st-d6 st-d7"> <div class="st-ba st-d8 st-d9 st-da st-bp st-db st-d0 st-dc st-dd" style="margin: 0px; padding: 1.5rem 1.5rem 0.75rem; font-family: "Source Sans Pro", sans-serif; font-size: 1.5rem; font-weight: 600; line-height: 1.5; text-transform: none; display: flex; align-items: center; max-height: 80vh; flex-direction: row;">Error</div> <div class="st-ba st-bb st-bc st-bd st-be st-bf st-de st-cz st-dc st-df st-dg" style="margin: 0px; padding: 0.75rem 1.5rem 1.5rem; color: rgb(49, 51, 63); font-size: 1rem; overflow-y: auto;"> <div class="st-emotion-cache-13jyg6u eh5ke330"> <div data-testid="stVerticalBlockBorderWrapper" data-test-scroll-behavior="normal" class="st-emotion-cache-0 e1f1d6gn0"> <div class="st-emotion-cache-1wmy9hl e1f1d6gn1"> <div width="704" data-testid="stVerticalBlock" class="st-emotion-cache-1n76uvr e1f1d6gn2"> <div data-testid="stVerticalBlockBorderWrapper" data-test-scroll-behavior="normal" class="st-emotion-cache-0 e1f1d6gn0"> <div class="st-emotion-cache-1wmy9hl e1f1d6gn1"> <div width="704" data-testid="stVerticalBlock" class="st-emotion-cache-1n76uvr e1f1d6gn2"> <div data-stale="false" width="704" class="element-container st-emotion-cache-hqlule e1f1d6gn4" data-testid="element-container"> <div class="stAlert" data-testid="stAlert"> <div role="alert" data-baseweb="notification" data-testid="stAlertContainer" class="stAlertContainer st-ba st-bb st-bc st-bd st-be st-bf st-ch st-dh st-di st-f8 st-dk st-dl st-dm st-dn st-do st-dp st-dq st-b6 st-b8 st-b9 st-b7 st-dr st-f6 st-ds st-b4 st-dt st-ai st-du st-dv st-dw st-dx"> <div class="st-au st-dy"> <div data-testid="stAlertContentError" class="st-emotion-cache-wmn9kq e1e4pi9i0"> <div class="st-emotion-cache-1m1jr3q e1eexb540"> <div data-testid="stMarkdownContainer" class="st-emotion-cache-1rsyhoq e1nzilvr5" style="width: 100%;"> <p>str: dsd</p> </div> </div> </div> </div> </div> </div> </div> <div data-stale="false" width="704" class="element-container st-emotion-cache-hqlule e1f1d6gn4" data-testid="element-container"> <div class="stButton" data-testid="stButton" style="width: 704px;"> <button kind="secondary" data-testid="stBaseButton-secondary" class="st-emotion-cache-1695wks ef3psqc13"> <div data-testid="stMarkdownContainer" class="st-emotion-cache-12h5x7g e1nzilvr5"> <p>Show Traceback</p> </div> </button> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <button aria-label="Close" class="st-dz st-e0 st-e1 st-e2 st-e3 st-e4 st-bp st-e5 st-b4 st-av st-aw st-ax st-ay st-az st-b0 st-b1 st-b2 st-e6 st-e7 st-e8 st-e9 st-ea st-d6 st-cc st-eb st-ec st-ed st-ee st-ai st-ck st-ef st-eg"> <svg width="10" height="10" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg" style="stroke: currentcolor;"> <path d="M9 1L5 5M1 9L5 5M5 5L1 1M5 5L9 9" stroke-width="2" stroke-linecap="round"></path> </svg> </button> </div> - Assistant
To prevent the Streamlit
st.dialogfrom closing when clicking outside of it, you can use themodalparameter in the@st.dialogdecorator and set it toTrue. This way, the dialog will behave as a modal dialog, requiring the user to interact with it before they can return to the main page.Here’s how you can modify your
show_exceptionfunction:import streamlit as st import traceback @st.dialog("Error", width="large", modal=True) # Set modal to True def show_exception(exception): st.error(f"{type(exception).__name__}: {str(exception)}") traceback_button = st.button("Show Traceback") if traceback_button: trace = traceback.extract_tb(exception.__traceback__) trace_details = [] for frame in trace: trace_details.append( f'File "{frame.filename}", line {frame.lineno}, in {frame.name}\n {frame.line}' ) st.code("Traceback:\n" + "\n".join(trace_details), language=None) - User
got error TypeError: dialog_decorator() got an unexpected keyword argument 'modal'
- Assistant