panel: panel does not interact properly with plotly.express in jupyter notebook
My jupyter lab extension list:
Versions of jupyter, plotly and panel:
In the current environment, panel and plotly work independently. However, the integration shown in the code below produced nothing. I also attached the screenshot of the jupyter notebook to show the output (blank). Panel integrates fine with hvplot.
import pandas as pd
import numpy as np
import panel as pn
from panel.interact import interact
import plotly.express as px
import hvplot.pandas
pn.extension("plotly")
# Create data
housing_transactions = pd.DataFrame(
{
"years": np.random.randint(2010, 2019, 100),
"sales": np.random.randint(53, 500, 100),
"foreclosures": np.random.randint(10, 147, 100),
}
).sort_values(["years", "sales"])
# Create scatter plot
scatter_plot = px.scatter(
housing_transactions,
x="sales",
y="foreclosures",
color="years",
title="Allegheny Sales/Foreclosures Correlation",
)
# Create bar plot
transactions_by_year = housing_transactions.groupby("years").sum().reset_index()
bar_plot = px.bar(
transactions_by_year, x="years", y="sales", title="Alleghany Sales by Year"
)
# Create row
row = pn.Row(scatter_plot, bar_plot)
row

About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (4 by maintainers)
Ah, this is very confusing, the issue is the
hvplot.pandasimport beforepn.extensionis run. If you change it around like this it should work:This is because
hvplot.pandasis trying to be helpful and is loading the extension itself. The problem with that is that once the extension is loaded additional dependencies likeplotlycannot be loaded in a subsequent call. I’ll think about how to fix this.@philippjfr and @pybokeh : Thanks again for your help with this issue. Yesterday, I upgraded jupyter. For reasons that I can’t fathom, the kernel was lost. I created a new environment with the exact same versions of libraries, and made sure that
import hvplot.pandasis afterpanel("plotly). I was able to run the programs smoothly. I truly appreciate your inputs! I would not have guessed this as the cause of the problem.Did you restart your kernel? In case that doesn’t work try clearing the notebook and reload the page as well.