streamlit / streamlit

Streamlit ā€” A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
35.64k stars 3.09k forks source link

Modal/pop-up widget #1360

Closed arraydude closed 7 months ago

arraydude commented 4 years ago

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.

Visits

andfanilo commented 4 years 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)
moises-catala-sonosuite commented 3 years ago

This feature would be a great addition!

marcbuilds commented 3 years ago

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.

durd07 commented 2 years ago

Hi,

Any update on this line?

Mohammadabd commented 2 years ago

Following...

Sriram-bb63 commented 2 years ago

I would love to get this feature asap

bbelescot commented 2 years ago

I think it'd be a killer feature! Following this :)

danielhangan commented 2 years ago

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")
ro1and commented 2 years ago

Following as well! This would be a really nice addition to Streamlit

tyrin commented 2 years ago

This feature would be super useful in a bunch of use cases:

abedhammoud commented 2 years ago

It would be a great feature to have! Thank you for the excellent work you have done already!

oliverfunk commented 2 years ago

Would be a great feature! Could show warning dialogs etc.

andfanilo commented 2 years ago

In the meantime you could try the modal example in the experimental section of the Hydralit Components repo by @TangleSpace

image

image

Have a nice day, Fanilo

corticalstack commented 2 years ago

@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?

lhlong commented 2 years ago

how's this going on?

PvanHengel commented 2 years ago

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!

andfanilo commented 2 years ago

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

MrDebugger commented 2 years ago

Following šŸ„¶

naorpeled commented 2 years ago

Would love to help with this if needed šŸ™

littleK0i commented 2 years ago

Following as well.

Behordeun commented 2 years ago

I am looking forward to the release of the pop-up feature. It will be a great one for all users.

koenvo commented 1 year ago

Not sure if useful but I created this project a while ago: https://github.com/teamtv/streamlit_modal

matipina commented 1 year ago

Following up!

jrieke commented 1 year ago

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!

jrieke commented 1 year ago

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.

Demo

https://user-images.githubusercontent.com/5103165/228372761-84890e83-7399-414f-b24b-4279baacb790.mp4

Proposed API for st.dialog

st.dialog(
    title,
    *,
    close_on_submit=True,
    clear_on_close=True,
    clear_on_submit=False,
    dismissible=True,
    key=None
)

Docstring

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:

But there are also some differences:

Parameters

Examples

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()

Open questions

  1. Should 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.
  2. Should we rename 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.
  3. Should we call the first parameter title (a bit closer to what it actually does) or label (a bit closer to widgets)?
  4. Should we have 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.
fplanque commented 1 year ago

Great!

  1. As proposed above is already great! Release it! ;) I would suggest to add an mode="form"|"container" param when you can. I am very much in favor of minimizing re-runs every time it's possible.
  2. 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.
  3. I prefer title. It definitely does not feel like a label, nor does the dialog feel like a widget.
  4. Two separate params seems absolutely fine to me.
shakamoushie commented 1 year ago

This feature was much awaited!

  1. I think st.dialog working like a form would be better, even though its child widgets wont be able to have independant logic. Basis the code, I assume columns are allowed within st.dialog.
  2. I would suggest that you rename st.form_submit_button to st.submit_button. All it would require is a global find-replace in any legacy code.
  3. 'title' seem appropriate for the first parameter.
  4. This would seem better: clear="close"|"submit"|False
aymeric-roucher commented 1 year ago

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.

kaankork commented 1 year ago

The demo looks great! When do you plan on releasing? šŸ˜„

abikkani1 commented 1 year ago

Also would love this!

Davipar commented 1 year ago

Amazing demo! looking forward to testing it!

dwvisser commented 1 year ago

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

kobic8 commented 1 year ago

am also intrested in pop-up dialog feature! :) thanks

kacper-kedzierski-kinesso commented 1 year ago

Awesome! looking forward giving it a try

nlykousas commented 1 year ago

I found this: https://experimental-modals.streamlit.app Does anyone know if this is the official yet unreleased modal functionality or some other component?

cquangc commented 1 year ago

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

mingjun1120 commented 1 year ago

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!

rotrigoh commented 1 year ago

Following :)

djsamyak commented 1 year ago

Would be great feature. Following!

DanielMajer24 commented 1 year ago

Following! This will be a great addition.

gsidsid commented 1 year ago

need this stat. looking forward

victorccaldas commented 1 year ago

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

yulevern commented 1 year ago

This is great please release it

tyrin commented 1 year ago

Turns on Patsy Cline... "Please release me, let me go....."

AunRaza21 commented 1 year ago

Demo looks amazing. Waiting for it.

julienbosse commented 1 year ago

The prototype looks great. Can't wait !

chrda81 commented 1 year ago

Any chance that this dialog feature is released earlier as mentioned on the roadmap forecast?

corticalstack commented 1 year ago

Here also awaiting release of this much needed element

rrhurtado commented 1 year ago

Waiting for the feature release. Thanks!

Frank17 commented 1 year ago

Also waiting on this feature!