-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modal/pop-up widget #1360
Comments
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, |
@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/ |
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. |
<!--⚠️ BEFORE CONTRIBUTING PLEASE READ OUR CONTRIBUTING GUIDELINES! https://github.com/streamlit/streamlit/wiki/Contributing --> ## Describe your changes Closes #1360 This PR adds a dialog layout container. This is exposed to users via the `@st.experimental_dialog` decorator. A function decorated with this decorated will render a dialog when being called. The body of the decorated function will be rendered as the dialog's content. It uses the fragment decorator (introduced in #8343) under the hood so that the dialog can be interacted with without triggering a full-app rerun. Example: ```python import streamlit as st @st.experimental_dialog("Streamlit Example Dialog") def example_dialog(some_arg: str, some_other_arg: int): st.write(f"You passed following args: {some_arg} | {some_other_arg}") # interacting with the text_input only re-runs `example_dialog` some_text_input = st.text_input("Type something:", key="example_dialog_some_text_input") # following write is updated when chaning the text_input inside the dialog st.write(f"You wrote '{some_text_input}' in the dialog") if st.button("Close the dialog"): st.rerun() if st.button("Open dialog"): example_dialog("Some string arg", 42) # following write is updated with the dialog's text input when the dialog was opened, the text input was interacted with and a re-run was triggered, e.g. by clicking the Close-button defined in `example_dialog` st.write(f"You wrote '{st.session_state.get('example_dialog_some_text_input', '')}' in the dialog") ``` ![Screenshot 2024-04-04 at 16 31 35](https://github.com/streamlit/streamlit/assets/3775781/751a43d1-7c6a-4642-8864-d08a5d286cb5) Since it uses the experimental fragment feature, it is exposed as experimental as well for now. ## GitHub Issue Link (if applicable) ## Testing Plan - Added Python and JavaScript unit tests - Added e2e playwright tests --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
This is finally merged and will be released in 1.34 in early May! You should also be able to test this with |
@jrieke: Is there a way to do a Our use case is as follows:
For this we need to be able to use the |
@jrieke
|
I had no issues using it. |
@sfc-gh-pkommini |
I'm using a docker container and I just replaced |
@sfc-gh-pkommini
|
@sfc-gh-pkommini Ah, this is not possible today. Can you open a new feature request on GitHub for this, so it doesn't get lost in here? I also have a few more comments on your use case but will add them to the new issue. @swagluke It's |
@jrieke |
@jrieke The show dialog collapses the file upload option sometimes when I am writing the missing columns this is my code def show_dialog():
def close_dialog(): |
## Describe your changes This PR adds a popover layout container. It consists of a button-like element and a container that opens when the button is clicked, e.g.: ```python with st.popover( "Open popover"): st.markdown("Hello World 👋") st.text_input("Whats your name?") ``` <img width="434" alt="image" src="https://github.com/streamlit/streamlit/assets/2852129/ec891bc1-8556-4db7-be3f-d8b226e15365"> Demo: https://popover-container-demo.streamlit.app/ ## GitHub Issue Link (if applicable) Solves some of the usecases discussed in streamlit#1360 ## Testing Plan - Added unit and e2e tests --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Follow-up question here, |
Has anyone tried
|
@LukasMasuch I am wondering whether this might be related to / fixed by #8533 |
Probably not :( is this happening whenever |
Would love to get some suggestions on this. Thanks in advance. |
Hi ! Great feature ! I am running in python 3.11 and nightly version installed but the st.rerun() does not close the dialog for me when clicking Cancel (only when clicking Delete). This seems strange because I see the page refreshing in the background. Here is the code I am using (taken from example and adapted a little to my usecase): @st.experimental_dialog("Delete existing user")
def delete_user_dialog(self, user_to_delete):
username = user_to_delete["name"]
st.write(f"Are you sure you want to delete {username}?")
col1, col2 = st.columns([1, 1])
if col1.button("Delete"):
self.perform_deletion_user(user_to_delete)
st.rerun()
if col2.button("Cancel"):
st.rerun() This very behaviour does not happen when I bind it to a button, but actually I would love to use it inside a on_change function for a data editor. (maybe there is another way of closing the dialog) |
Hi Team,
|
Also, can we make it flexible to not pass the "title" in the dialog, as we can pass a key to the dialog to identify it but the mandatory title is forcing me to show some title on UI. |
@Stefano97 would you be able to share the full code for this? I tried to add your code into a sample app and do not have any issues. |
Interesting use-case! The issue seems to come from the fact that the dialog (fragment) is called via the callback. If you refactor that to if st.button("Cancel", key="sample_key"):
show_dialog() it should work (actually you will see a warning that Thanks for the feedback, we are going to discuss this with the team! |
Hey @pri2si17-1997 , I tried to reproduce it but the following example app works fine for me: import streamlit as st
st.title("Echo Bot")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
@st.experimental_dialog("Echo Chat")
def open_chat_dialog():
chat_messages = st.container()
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with chat_messages.chat_message(message["role"]):
st.markdown(message["content"])
# React to user input
if prompt := st.chat_input("What is up?"):
# Display user message in chat message container
chat_messages.chat_message("user").markdown(prompt)
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
response = f"Echo: {prompt}"
# Display assistant response in chat message container
with chat_messages.chat_message("assistant"):
st.markdown(response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response})
if st.button("Open chat"):
open_chat_dialog() Could you share your code so that we can have a look? |
@dilipthakkar-metacube, can you describe or, even better, share a screenshot of your use case so I can see what you're trying to do? The issue with removing the title/making it optional is that we still have to show the X on the top right, so we'd either have a big blank space at the top of the dialog or have the X button and elements overlap, if there's no title. |
Hi @raethlein , It would be great if we would be able to call the fragment from a callback and we really need this feature in one of our production level application which is built top on streamlit. Let me explain the exact use case: We have a custom streamlit component which has a button which is bind to a python callback. And on the click of that button we want to show a modal box to users to confirm the changes and provide some other information also. It would be great help if you will consider this request. Thank you for giving us one of the best tool to create web applications with less code. |
@dilipthakkar-metacube can you open a new GitHub issue as a feature request for this use case? In here it will only get lost since the issue is already closed. We've been thinking about how to make confirmation dialogs/buttons even easier to use, so would be very happy to hear about your use case in detail on the new issue and see what others think! |
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: #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.
The text was updated successfully, but these errors were encountered: