Skip to content
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

TQDM-style progress bar #160

Closed
treuille opened this issue Sep 21, 2019 · 14 comments
Closed

TQDM-style progress bar #160

treuille opened this issue Sep 21, 2019 · 14 comments
Labels
type:enhancement Requests for feature enhancements or new features

Comments

@treuille
Copy link
Contributor

treuille commented Sep 21, 2019

Problem

The st.progress API is quite low level:

  • it cannot be composed with iterators
  • it doesn't automatically compute percentages or time remaining

Solution

MVP

It would be great if we had another primitive that behaved like tqdm, with a similar (or identical?) API.

Possible additions

Should we make a special widget for this?

@treuille treuille added the type:enhancement Requests for feature enhancements or new features label Sep 21, 2019
@jeremyjordan
Copy link

The current progress widget, as you mentioned, feels too low level for everyday use. Here's a minimum implementation that would capture the desirable level of abstraction. The nice thing about tqdm is you can simply wrap the object you're iterating over and it will figure out how to report progress.

import streamlit as st
import time


class tqdm:
    def __init__(self, iterable, title=None):
        if title:
            st.write(title)
        self.prog_bar = st.progress(0)
        self.iterable = iterable
        self.length = len(iterable)
        self.i = 0

    def __iter__(self):
        for obj in self.iterable:
            yield obj
            self.i += 1
            current_prog = self.i / self.length
            self.prog_bar.progress(current_prog)


for i in tqdm(range(200), title='tqdm style progress bar'):
    time.sleep(0.05)

st.balloons()

@landmann
Copy link

The problem I have now is that the written title coming from st.write(title) doesn't disappear. Any thoughts?

@nickvazz
Copy link

I think the modification of using the placeholders st.empty() for the title/progress bar would accomplish what you're looking for.

Changing

    def __init__(self, iterable, title=None):
        if title:
            st.write(title)
        self.prog_bar = st.progress(0)

to

    def __init__(self, iterable, title=None):
        if title:
            st_title.write(title)
        self.prog_bar = st_progress_bar.progress(0)

and adding st_title and st_progress to the top and bottom

st_title = st.empty() # add this at top
st_progress = st.empty() # add this at top

full code below:

import streamlit as st
import time


st_title = st.empty()
st_progress_bar = st.empty()

class tqdm:
    def __init__(self, iterable, title=None):
        if title:
            st_title.write(title)
        self.prog_bar = st_progress_bar.progress(0)
        self.iterable = iterable
        self.length = len(iterable)
        self.i = 0

    def __iter__(self):
        for obj in self.iterable:
            yield obj
            self.i += 1
            current_prog = self.i / self.length
            self.prog_bar.progress(current_prog)



for i in tqdm(range(200), title='tqdm style progress bar'):
    time.sleep(0.05)

st_title.empty()
st_progress_bar.empty()

st.balloons()

@Wirg
Copy link

Wirg commented Dec 3, 2020

I think you may be interested in stqdm :

This takes the best from tqdm & streamlit to :

  • update only when necessary and avoid slowing down your program too much
  • have a progress bar in your frontend and backend
  • add a description and all the tqdm options
  • add the tqdm details to your frontend (% completion, ETA ...)
    demo gif

Upcoming features :

  • better handling of multiple progress bars
  • colors

@AndreyGurevich
Copy link

@Wirg, is it compatible with pandas.apply inside streamlit?

@Wirg
Copy link

Wirg commented Jan 21, 2021

@AndreyGurevich do you mean the progress_apply from tqdm ?

@AndreyGurevich
Copy link

Yes

@andfanilo
Copy link
Contributor

@Wirg I've just discovered your stqdm package, it's neat!
I don't recall seeing it in the forum though, if that's the case do you mind posting it in a new topic so other users can discover it :) ?

Best,
Fanilo

@Wirg
Copy link

Wirg commented Jan 21, 2021

@AndreyGurevich Yes, it works. Stqdm inherits from tqdm.
So if you want to use it with pandas, you just have to run stqdm.pandas() instead of the tqdm equivalent.
I will had this example to the docs.

from time import sleep
import pandas as pd
from stqdm import stqdm

stqdm.pandas()

pd.Series(range(50)).progress_map(lambda x: sleep(1))

@andfanilo Thanks. Sure. Where should I ?

@andfanilo
Copy link
Contributor

@Wirg Oops I failed at copying the correct link to the forum XD here it is!
Hope to see you there :)

@AndreyGurevich
Copy link

@Wirg great, thank you!

@treuille
Copy link
Contributor Author

This is great! Could we release this as a component for the components gallery?

@Wirg
Copy link

Wirg commented Feb 28, 2021

Thank you for your advice and support.

@treuille

This is great! Could we release this as a component for the components gallery?

Is this something else that what I already did ?

@randyzwitch
Copy link
Contributor

Closing, as this now exists as a Streamlit component!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

No branches or pull requests

9 participants