/
notebook.py
77 lines (64 loc) · 2.65 KB
/
notebook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""This module contains functionality used by awesome-panel in Notebooks"""
import panel as pn
import param
from awesome_panel_extensions.widgets.link_buttons import (
BinderLinkButton,
NBViewerLinkButton,
PanelLinkButton,
)
pn.extension()
DEFAULT_HEADER_MESSAGE = """\
[Panel](https://panel.holoviz.org) is a framework for creating powerful, reactive analytics apps in
Python using the tools you know and love. 💪🐍❤️.
This notebook is brought to you by [awesome-panel.org](https://awesome-panel.org).
"""
class Header(pn.Column):
"""Extension Implementation"""
def __init__( # pylint: disable=too-many-arguments
self,
folder: str,
notebook: str,
repository: str = "marcskovmadsen/awesome-panel-extensions",
branch: str = "master",
message: str = DEFAULT_HEADER_MESSAGE,
**params,
):
params["sizing_mode"] = params.get("sizing_mode", "stretch_width")
super().__init__(**params)
self.binder_link_button = BinderLinkButton(
repository=repository, branch=branch, folder=folder, notebook=notebook,
)
self.nbviewer_link_button = NBViewerLinkButton(
repository=repository, branch=branch, folder=folder, notebook=notebook,
)
self.panel_link_button = PanelLinkButton(theme="dark")
text = pn.pane.Markdown(message, sizing_mode="stretch_width")
buttons = pn.Row(
self.panel_link_button,
self.binder_link_button,
self.nbviewer_link_button,
Style(container_width="90%"),
sizing_mode="stretch_width",
)
self[:] = [buttons, text]
class Style(pn.pane.HTML):
"""Class for styling a reference notebook"""
container_width = param.String(default="100%")
# In order to not be selected by the `pn.panel` selection process
# Cf. https://github.com/holoviz/panel/issues/1494#issuecomment-663219654
priority = 0
# The _rename dict is used to keep track of Panel parameters to sync to Bokeh properties.
# As value is not a property on the Bokeh model we should set it to None
_rename = {
**pn.pane.HTML._rename,
"container_width": None,
}
def __init__(self, **params):
super().__init__(**params)
self._update_object_from_parameters()
# Don't name the function
# `_update`, `_update_object`, `_update_model` or `_update_pane`
# as this will override a function in the parent class.
@param.depends("container_width", watch=True)
def _update_object_from_parameters(self, *_):
self.object = f"<style>.container {{ width:{self.container_width} !important; }}</style>"