Open andhuang-CLGX opened 3 years ago
I've been wanting this as well.
I truly believe for example the FastTemplates could be made working if somebody had the time.
The notebook is also a deployment target!
Being able to easily create beutiful tools and apllications to notebook users is something unique that Panel could support doing well.
Just something to start with so it's easier to develop in notebook and then replace it with an actual template once ready. It probably should inherit from the base Template class.
import param
import panel as pn
pn.extension()
class NotebookPlaceholderTemplate(pn.viewable.Viewer):
main = param.List()
sidebar = param.List()
header = param.List()
title = param.String()
def __panel__(self):
title = pn.pane.Markdown(f"# {self.title}", sizing_mode="stretch_width")
# pastel blue
header_row = pn.Row(
title,
*self.header,
sizing_mode="stretch_width",
styles={"background": "#e6f2ff"},
)
main_col = pn.WidgetBox(*self.main, sizing_mode="stretch_both")
sidebar_col = pn.WidgetBox(
*self.sidebar, width=300, sizing_mode="stretch_height"
)
return pn.Column(
header_row,
pn.Row(sidebar_col, main_col, sizing_mode="stretch_both"),
sizing_mode="stretch_both",
min_height=400,
)
NotebookPlaceholderTemplate(
main=[pn.pane.Markdown("Main content")],
sidebar=[pn.pane.Markdown("Sidebar content")],
header=[pn.pane.Markdown("Header content")],
title="Title",
)
If it's in a notebook it should probably start with the sidebar collapsed, to reflect the narrower width of a notebook cell compared to the deployed dashboard. And I'm not sure it really needs the title to be displayed, at least not as a whole bar like that; does a notebook cell need that?
But maybe we have different needs here -- I'm wanting something that is something actually plausible to use in the notebook, but lets the same code be used for a deployment, while maybe other people want something that's only for debugging, and would never actually be used in the notebook.
Sidebar can be disabled if it's not populated with values. I see value in both.
Collapsed temporarily, but expandable. Yes, omitted entirely if it's not populated, in a notebook, but even if it's populated, it would usually have controls for a plot, and the important bit is to show the plot, with the user optionally being able to bring up the controls. When you try to cram a dashboard into a notebook cell, what usually happens right now is that the fixed-sized controls end up crowding out the plots entirely, when the controls aren't the important thing, the plot or table is.
I am new to Panel and ran into this recently, so I am following up to see where things currently stand...
Are Templates still not functional in a notebook environment? If so, are there any workarounds to using Templates (and related things such as modals) from notebooks?
Thanks!
I am not aware of modals being supported but the above code is a workaround with main/sidebar/header kwargs. Once you work outside the notebook, you can swap it out with a proper template.
You can use this modal in a notebook https://github.com/awesome-panel/panel-modal. There is an unfinished PR to add it to Panel. Will be done some day.
Even if it's just a simple:
pn.templates.PseudoTemplate = pn.Row({"sidebar": pn.Column(), "main": pn.Column()})
So it's easier to work with jupyter notebooks, and once everything is finished, the user can just swap PseudoTemplate with MaterialTemplate or something