Closed arraydude closed 7 months ago
This would be an interesting usecase.
I know if I had a Modal at hand, if possible I'd like to use it like I use the sidebar, that is enable Streamlit widgets inside a modal (button, file_uploader...).
That would require a bit of API design thinking though around composing what's inside the modal with different st calls inside, and managing enter/exit calls through a context manager.
quickly jotting an idea that really is just an idea without too much thinking:
df = None
with st.modal(label_ok_button, label_cancel_button) as m:
m.header("Hello world, input your file")
f = m.file_uploader(...)
while not f:
m.markdown("Waiting for your input")
df = process_file(f)
This feature would be a great addition!
Also going to add that this would be hugely useful for some projects I'm working on. My use case is that the user is committing to sending an external API POST request, but needs a modal dialogue with a confirmation of what is about to be sent (a list of the variables prepared for the request), to ensure they are performing the correct action.
I'll add that perhaps this is veering a bit outside the scope of Streamlit as a whole, so understanadbly might not be where the focus should be for the team.
Hi,
Any update on this line?
Following...
I would love to get this feature asap
I think it'd be a killer feature! Following this :)
I also needed this feature but I found a temporary workaround using st.expander()
modal = st.expander("Advanced options")
option_1 = modal.checkbox("Option 1")
option_2 = modal.checkbox("Option 2")
option_3 = modal.checkbox("Option 3")
option_4 = modal.checkbox("Option 4")
if option_1:
st.write("Hello world 1")
if option_2:
st.write("Hello world 2")
if option_3:
st.write("Hello world 3")
if option_4:
st.write("Hello world 4")
Following as well! This would be a really nice addition to Streamlit
This feature would be super useful in a bunch of use cases:
It would be a great feature to have! Thank you for the excellent work you have done already!
Would be a great feature! Could show warning dialogs etc.
In the meantime you could try the modal example in the experimental section of the Hydralit Components repo by @TangleSpace
Have a nice day, Fanilo
@andfanilo had a look at the example modal popup from the hydralit package, could'nt see if tehre's a way to pass in id or other identifier should there be multipel buttons (say in a list) that potentially can call the popup?
how's this going on?
Agree this is a great feature request, where can we find a list of all features and vote them up down? This one belongs at the top!
There's a roadmap here: https://share.streamlit.io/streamlit/roadmap/ But I think the thumbs up counter for the issue on the first message is part of what the team considers to prioritize, alongside other more internal stuff. Fanilo
Following š„¶
Would love to help with this if needed š
Following as well.
I am looking forward to the release of the pop-up feature. It will be a great one for all users.
Not sure if useful but I created this project a while ago: https://github.com/teamtv/streamlit_modal
Following up!
Hey all! We're currently figuring out the best way to do this and working on a prototype. We won't launch this immediately but I guess sometime during the summer. Will let you know more soon!
Hey all! We've been prototyping quite a bit in the past few weeks. We now have a first draft for how st.dialog
might work. We're still figuring out details but I thought I'd already post our proposal here to get some first feedback! Please let me know what you think, especially about the open questions at the end.
https://user-images.githubusercontent.com/5103165/228372761-84890e83-7399-414f-b24b-4279baacb790.mp4
st.dialog
st.dialog(
title,
*,
close_on_submit=True,
clear_on_close=True,
clear_on_submit=False,
dismissible=True,
key=None
)
Create a modal dialog that shows up as an overlay on top of the app.
A dialog is a container that contains elements and widgets. To add elements to a dialog, you can use with
notation or just call methods directly on the dialog. See examples below.
Dialogs work similarly to forms:
st.form_submit_button
.st.button
and st.download_button
cannot be added to dialogs.But there are also some differences:
dismissible
is set to False)..open()
method in order to show them. See examples below.close_on_submit
is set to True (the default). If it is set to False, you need to manually close the dialog by calling .close()
on it. See examples below..close()
on the return object. This is useful e.g. to validate widget input and only close the dialog if itās valid. Defaults to True. Create a simple dialog that just shows text to the user:
import streamlit as st
dial = st.dialog("Warning")
dial.write("Here's a warning!")
if st.button("Show warning"):
dial.open()
Of course, you could also show charts, dataframes, or any other static element instead. Note that this dialog doesnāt contain a submit button. Thatās valid as long as you donāt set dismissible
to False.
Create a dialog with interactive widgets and retrieve their values:
import streamlit as st
dial = st.dialog("Data entry")
with dial:
name = st.text_input("What's your name?")
age = st.number_input("What's your age?", min_value=0)
submitted = st.form_submit_button("Submit")
if st.button("Enter data"):
dial.open()
if submitted:
st.write(f"Your name is {name} and you are {age} years old.")
Note that you should always create the dialog outside of where you are actually opening it! Here, we are creating the dialog on the top level of the code. Inside the if st.button(āEnter dataā)
block, we are just calling dial.open()
. If you would also create the dialog inside of that block, it would be impossible to retrieve name
and age
, the return values of the widgets: the dialog code would only be run directly after the viewer pressed the āEnter dataā
button. Once they click the submit button inside the dialog, the āEnter dataā
button would return False again, and the dialog code wouldnāt be called at all ā therefore not setting name
and age
.
Create a dialog that is closed programmatically, e.g. after validating the user input:
import streamlit as st
forbidden_animals = ["Lion", "Snake", "Shark"]
dial = st.dialog("Animal check", close_on_submit=False)
with dial:
animal = st.text_input("Enter the animal")
if st.form_submit_button("Submit"):
if animal in forbidden_animals:
st.error("This animal is forbidden! Try another one.")
else:
dial.close()
if st.button("Check an animal"):
dial.open()
st.dialog
work like a form (as proposed above) or just like a general container that reruns on every interaction with a widget? The nice thing about having it like a form is that it saves us a whole lot of trouble with the execution model because the app only reruns when you submit/close the dialog. st.form_submit_button
to st.submit_button
? Might be a nice clean up but would be annoying to people who currently use st.form_submit_button
in their app. title
(a bit closer to what it actually does) or label
(a bit closer to widgets)?clear_on_close
and clear_on_submit
as two separate parameters or should we merge them toclear="close"|"submit"|False
? Might be cleaner but then weād either deviate from the API of st.form
(which has clear_on_submit
) or weād need to deprecate clear_on_submit
in st.form
. Great!
mode="form"|"container"
param when you can. I am very much in favor of minimizing re-runs every time it's possible.st.submit_button
is much nicer. You could phase out the other one with a very clear warning message that explicitly says what code to change to what.title
. It definitely does not feel like a label, nor does the dialog feel like a widget.This feature was much awaited!
Currently I have been searching a long time for a way for user to display/hide a big text without taking up the huge space that st.expander
currently takes. So I'm also waiting for this release!
Regarding point 1, I think it's fine if it works like a form, most usecases won't need reruns.
The demo looks great! When do you plan on releasing? š
Also would love this!
Amazing demo! looking forward to testing it!
It's probably out of scope for the proposal shared above, but I would love if the dialog could have its height and width specified, and be able to scroll lengthy contents with its own scrollbar. One example of this: https://getbootstrap.com/docs/5.3/components/modal/#scrolling-long-content
am also intrested in pop-up dialog feature! :) thanks
Awesome! looking forward giving it a try
I found this: https://experimental-modals.streamlit.app Does anyone know if this is the official yet unreleased modal functionality or some other component?
This is incredible! Is there a way for us to look at the code? This is exactly the type of thing I would like to build
I found this: https://experimental-modals.streamlit.app Does anyone know if this is the official yet unreleased modal functionality or some other component?
It is still not officially working, I have just tried it out. Hope the Streamlit Team can release this feature ASAP because it really suits my case!
Following :)
Would be great feature. Following!
Following! This will be a great addition.
need this stat. looking forward
The demo is perfectly what everyone needs, and seems to be ready for release. Also being able to set height and width is nice, but not necessary for first launch. It's perfect as is
This is great please release it
Turns on Patsy Cline... "Please release me, let me go....."
Demo looks amazing. Waiting for it.
The prototype looks great. Can't wait !
Any chance that this dialog feature is released earlier as mentioned on the roadmap forecast?
Here also awaiting release of this much needed element
Waiting for the feature release. Thanks!
Also waiting on this feature!
Problem
As a user I would like to show some specific data within a modal
Solution
https://baseweb.design/components/modal/
Additional context
User question: https://github.com/streamlit/streamlit/issues/1337
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
If you'd like the Streamlit team to prioritize this feature request, please use the š (thumbs up emoji) reaction in response to the initial post.