Plotly with pyscript in Django HTML page

I am trying to integrate Plotly with the new method of using Python on an HTML page.

So I am trying to run this example:


    <meta charset="utf-8">
    <link rel="stylesheet" href="" />
    <script defer src=""></script>

      - plotly-express

    <center><h3>Wait it took long time to load</h3></center>
    <div id="mpl"></div>
      <py-script output="mpl">
import as px
df ="year == 2007").query("continent == 'Europe'")
df.loc[df['pop'] < 2.e6, 'country'] = 'Other countries' # Represent only large countries
fig = px.pie(df, values='pop', names='country', title='Population of European continent')

After a few minutes :frowning: I get an error !

JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/site-packages/plotly/io/", line 532, in webbrowser.get() AttributeError: module 'webbrowser' has no attribute 'get' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/lib/python3.10/site-packages/_pyodide/", line 429, in eval_code .run(globals, locals) File "/lib/python3.10/site-packages/_pyodide/", line 300, in run coroutine = eval(self.code, globals, locals) File "", line 6, in File "/lib/python3.10/site-packages/plotly/", line 3400, in show return, *args, **kwargs) File "/lib/python3.10/site-packages/_plotly_utils/", line 36, in __getattr__ class_module = importlib.import_module(rel_module, parent_name) File "/lib/python3.10/importlib/", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/lib/python3.10/site-packages/plotly/io/", line 534, in except webbrowser.Error: AttributeError: module 'webbrowser' has no attribute 'Error' )

Take a look here.
In example 2 it is said that pyscript doesn’t support Plotly for now (the guy use Brokeh because of that)
I hope that help you

1 Like