Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
holoviz
GitHub Repository: holoviz/panel
Path: blob/main/doc/_static/json/vscode-snippets-python.json
2012 views
1
{
2
"Panel App": {
3
"prefix": "import panel",
4
"body": [
5
"import panel as pn",
6
"",
7
"pn.extension(sizing_mode=\"stretch_width\")",
8
"",
9
"TEXT = \"Panel\"",
10
"",
11
"length = pn.widgets.IntSlider(value=len(TEXT), end=len(TEXT), name=\"length\")",
12
"",
13
"def text(value):",
14
" return TEXT[:value]",
15
"",
16
"layout = pn.Column(length, pn.bind(text, length))",
17
"",
18
"pn.template.FastListTemplate(site=\"Panel\", title=\"App\", sidebar=[length], main=[layout]).servable()"
19
]
20
},
21
"Panel ReactiveHTML component": {
22
"prefix": [
23
"import panel",
24
"from panel.reactive"
25
],
26
"body": [
27
"import panel as pn",
28
"import param",
29
"from panel.reactive import ReactiveHTML",
30
"",
31
"pn.extension()",
32
"",
33
"",
34
"class CustomComponent(ReactiveHTML):",
35
" index = param.Integer(default=0)",
36
"",
37
" _template = '<img id=\"slideshow\" src=\"https://picsum.photos/800/300?image=${index}\" onclick=\"${_img_click}\"></img>'",
38
"",
39
" def _img_click(self, event):",
40
" self.index += 1",
41
"",
42
"CustomComponent(width=500, height=200).servable()"
43
]
44
},
45
"Panel Viewer component": {
46
"prefix": [
47
"import panel",
48
"from panel.viewable"
49
],
50
"body": [
51
"import param",
52
"import panel as pn",
53
"",
54
"from panel.viewable import Viewer",
55
"",
56
"class CustomComponent(Viewer):",
57
"",
58
" value = param.Parameter()",
59
"",
60
" def __init__(self, **params):",
61
" super().__init__(**params)",
62
" self._layout = None",
63
" ",
64
"",
65
" def __panel__(self):",
66
" if not self._layout:",
67
" self._layout = self._get_layout()",
68
" ",
69
" return self._layout",
70
"",
71
" def _get_layout(self):",
72
" return pn.Column(\"# Custom Component\", self.param.value)",
73
"",
74
"if pn.state.served:",
75
" pn.extension(sizing_mode=\"stretch_width\")",
76
" ",
77
" pn.Column(",
78
" CustomComponent",
79
" ).servable()"
80
]
81
}
82
}
83
84