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

progress bar in jupyter notebook #49

Open
samsja opened this issue Oct 29, 2021 · 8 comments
Open

progress bar in jupyter notebook #49

samsja opened this issue Oct 29, 2021 · 8 comments

Comments

@samsja
Copy link

samsja commented Oct 29, 2021

Hey,

I discover a issue while using ProgressBar in a notebook, the progress bar is print at each new iteration instead of refreshing as excepted.

How to reproduce the error:

launch the following code in either jupyter lab or jupyter notebook.

using ProgressBars
for i in tqdm(0:3)
    sleep(0.1)
end

here is the output:

2021-10-29-125616_1920x1080_scrot

Is there a way to proprely use progress bar in notebook ? Maybe like tqdm.auto_notebook ?

Otherwise I would be glad to work on a PR.

Thanks in advance

@khdlr
Copy link
Member

khdlr commented Oct 29, 2021

Hi samsja, that's odd. It might be that Jupyter doesn't support some of the ANSI escape sequences used. The way tqdm.auto_notebook does this is by providing a custom ipywidget. This might be quite a lot of work to implement for ProgressBars.jl. But the newlines should definitely be addressed.

I don't have much time to work on this library at the moment, but I'll gladly accept a PR :)

@dnadlinger
Copy link

@samsja: Did you get a chance to look into this? Seems to be the same issue as #44.

@samsja
Copy link
Author

samsja commented Mar 28, 2022

Hey @dnadlinger I did not pursue further on this issue

@oameye
Copy link

oameye commented Oct 23, 2022

Would be nice if someone got it working.

@MilesCranmer
Copy link
Contributor

I'm trying to get this working. In principle this snippet:

go_to_start_of_line(output_stream::IO) = print(output_stream, "\r")

should work fine. But I think the other ansi escape sequences:

erase_to_end_of_line(output_stream::IO) = print(output_stream, "\033[K")
move_up_1_line(output_stream::IO) = print(output_stream, "\033[1A")
move_down_1_line(output_stream::IO) = print(output_stream, "\033[1B")

do not work for Jupyter, so need to be tweaked if a notebook is detected.

@MilesCranmer
Copy link
Contributor

MilesCranmer commented Feb 8, 2023

My sense is that these ANSI symbols are not supported in Jupyter: jupyter/notebook#2567. So this will not work without modifications. It looks like ANSI sequences are simply stripped: jupyter/notebook#444, rather than printed - which is why nothing else shows up.

One hacky solution to get this working is to print the entire progress bar (including multi-line prefixes/postfixes) to a single line of text, and then overwrite it with \r followed by spaces. However, for this, you would need to know the width of the Jupyter cell output, and update the width if the user changes the window size. I don't think this is possible for Jupyter (?).

A cleaner solution would be to use https://github.com/JuliaGizmos/Interact.jl to implement an actual Jupyter widget (like tqdm does). Or even just normal IJulia.jl display and clear_output.

@3f6a
Copy link

3f6a commented Aug 29, 2023

Related: timholy/ProgressMeter.jl#271, microsoft/vscode#118833

@dev10110
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants