Spaces:
Sleeping
Sleeping
Create app3.py
Browse files
app3.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import panel as pn
|
| 2 |
+
|
| 3 |
+
# Create a Panel app with centered title
|
| 4 |
+
title = pn.pane.HTML("<h1 style='text-align: center;'>My Panel App</h1>", width=300)
|
| 5 |
+
|
| 6 |
+
# Create a toggleable sidebar with three horizontal lines icon
|
| 7 |
+
toggle_sidebar = pn.widgets.Button(name='☰', button_type='primary', width=30, height=30)
|
| 8 |
+
toggle_sidebar.js_on_click(args={'sidebar': toggle_sidebar}, code="""
|
| 9 |
+
if (sidebar.width == 0) {
|
| 10 |
+
sidebar.width = 200;
|
| 11 |
+
buttons.css_classes = ['visible'];
|
| 12 |
+
} else {
|
| 13 |
+
sidebar.width = 0;
|
| 14 |
+
buttons.css_classes = ['hidden'];
|
| 15 |
+
}
|
| 16 |
+
""")
|
| 17 |
+
|
| 18 |
+
# Create buttons for the toggleable sidebar
|
| 19 |
+
button1 = pn.widgets.Button(name='Button 1')
|
| 20 |
+
button2 = pn.widgets.Button(name='Button 2')
|
| 21 |
+
button3 = pn.widgets.Button(name='Button 3')
|
| 22 |
+
|
| 23 |
+
# Create a column layout for the buttons inside the toggleable sidebar
|
| 24 |
+
buttons = pn.Column(button1, button2, button3, sizing_mode='stretch_height', background='#f6f6f6', css_classes=['hidden'])
|
| 25 |
+
|
| 26 |
+
# Combine the title, toggle button, and sidebar
|
| 27 |
+
app = pn.Column(
|
| 28 |
+
pn.Row(toggle_sidebar),
|
| 29 |
+
pn.Row(
|
| 30 |
+
pn.Column(title, pn.layout.Spacer(height=10)),
|
| 31 |
+
pn.layout.Divider(),
|
| 32 |
+
pn.Row(buttons, sizing_mode='stretch_width'),
|
| 33 |
+
sizing_mode='stretch_both',
|
| 34 |
+
align='center',
|
| 35 |
+
),
|
| 36 |
+
sizing_mode='stretch_both',
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Run the app
|
| 40 |
+
app.servable()
|