Cannot display figures when running from terminal/REPL
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python
- Domain
- data-visualization
Research direction
Start by locating the chart rendering or to_html entry point and review tqdm's autonotebook.py approach for detecting notebook execution. The work is complete when charts can open in a browser from a terminal or REPL while existing notebook behavior remains supported.
Written by the indexing model from the issue text.
Description
I regularly use a REPL or a terminal to run Python code.
Currently, it is not possible to display your charts in a browser tab when running code from a terminal.
In plotly, you can call fig.show(), and the library will automatically detect that it is not running in an IPython notebook and will open the figure in a browser window.
Here is a workaround that would be relatively easy to add:
import time
import tempfile
from pathlib import Path
import webbrowser
def show_xy(chart, **kwargs):
with tempfile.TemporaryDirectory() as temp_dir:
# Saves chart to a temporary HTML file
file_name = Path(temp_dir).joinpath("fig.html")
chart.to_html(file_name, **kwargs)
# Opens new browser tab with the chart.
webbrowser.open("file://" + str(file_name.absolute()), new=2)
# Makes sure the file is not deleted before the browser loads it.
time.sleep(2)
It is also possible to detect whether the code is being run in a notebook. Here is tqdm's code to handle this.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 76
- Avg merge
- 1h 7m
- Merged PRs (30d)
- 8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reflex-dev/xy
-
needs investigate performance
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
reflex-dev/xy#169 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
reflex-dev/xy#516 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
reflex-dev/xy#512 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
reflex-dev/xy#510 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
reflex-dev/xy#505 ·
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100