Hi there,
I was trying the last example shown here: Plotly — Panel v0.13.1 with two different .servable()
methods mentioned in the title, and found the inconsistent rendering pattern, so I am wondering what’s the difference, and what’s the better practice?
- Example 1: Call
.servable()
on a Pane object
import panel as pn
import plotly.express as px
import pandas as pd
pn.extension('plotly', template="fast", sizing_mode='stretch_width')
data = pd.DataFrame([
('Monday', 7), ('Tuesday', 4), ('Wednesday', 9), ('Thursday', 4),
('Friday', 4), ('Saturday', 4), ('Sunay', 4)], columns=['Day', 'Orders']
)
fig = px.line(data, x="Day", y="Orders")
fig.update_traces(mode="lines+markers", marker=dict(size=10), line=dict(width=4))
fig.layout.autosize = True
pn.pane.Plotly(fig, config={'responsive': True}, sizing_mode='stretch_both').servable()
This resulted (the plot was rendered properly in the card with margins):
- Example 2: call
.servable()
on a template
import pandas as pd
import panel as pn
import plotly.express as px
pn.extension('plotly', sizing_mode='stretch_width')
data = pd.DataFrame([
('Monday', 7), ('Tuesday', 4), ('Wednesday', 9), ('Thursday', 4),
('Friday', 4), ('Saturday', 4), ('Sunay', 4)], columns=['Day', 'Orders']
)
fig = px.line(data, x="Day", y="Orders")
fig.update_traces(mode="lines+markers", marker=dict(size=10), line=dict(width=4))
fig.layout.autosize = True
responsive = pn.pane.Plotly(fig, config={'responsive': True})
template = pn.template.FastGridTemplate()
template.main[:3, :] = pn.panel(responsive, sizing_mode='stretch_both')
template.servable();
This resulted (The plot wasn’t rendered properly in the card, where the bottom margin was missing):