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.
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:
It is also possible to detect whether the code is being run in a notebook. Here is tqdm's code to handle this.