Hi all,
kindly please advise how to make customization for header in panel for example adding more than 1 of logo or image, make background image, link, etc like in panel website
thanks
Hi all,
kindly please advise how to make customization for header in panel for example adding more than 1 of logo or image, make background image, link, etc like in panel website
Hi @Marc
I just show you awesome panel, while waiting new version of awesome panel to be compatible with the latest panel, kindly please advise how did you do for adding some images/logo and text in this header
Hi,
You have to provide content to the header, for instance:
image = ...
header = pn.Row(image)
pn.template.VanillaTemplate(
title='Title',
header=header
...
)
Hi @Theom , many thanks for your advise. It works, however is that any clue how custom the image for example width, height of the image since i try wth this code not working:
image = āhttps://www.markdownguide.org/assets/images/tux.pngā
header = pn.Row((image),align=ācenterā,width=100, height=20)
pn.template.VanillaTemplate(
title=āTitleā,
header=header,
logo = āassets/scipy.pngā
).servable()
alignment also only center, couldnāt put as right or center, only left(the default)
thanks and regards
Hi @rh1
Let me have a look.
You have some great questions rh1. To take your questions to the next level please provide the code as
Minimal, Reproducible Examples in fenched code blocks.
If the question is very clea and has a minimal, reproducible code example, then its easier for the community to understand your exact problem, find an answer and have time to help the next in line
Hi @Marc , thanks for your reply. My previous reply already contain the minimal code, I will put it again in here, now able to adjust width and height, still pending the position of image:
Result
Code
import panel as pn
pn.extension()
image = āhttps://www.markdownguide.org/assets/images/tux.pngā
header = pn.Row((image),align=ācenterā,width=100, height=20)
pn.template.VanillaTemplate(
title=āTitleā,
header=header,
logo = āassets/scipy.pngā
).servable()
thanks
Lets take a small detour to learn how to make action and header bars in general.
Some of the key features to use are
Row
to layout components in a rowSpacer
and HSpacer
to align things left, center and right.styles
to change the text color
or the background
align
to align widgets and panes.from asyncio import sleep
from datetime import datetime
import panel as pn
from panel import HSpacer, Spacer
pn.extension()
image = "https://www.markdownguide.org/assets/images/tux.png"
file_menu = pn.widgets.MenuButton(
name="File", button_type="primary", items=["Save"], width=60, margin=0, align="center"
)
help_menu = pn.widgets.MenuButton(
name="Help", button_type="primary", items=["About"], width=60, margin=0, align="center"
)
async def timer():
while True:
yield datetime.now().strftime("%H:%M:%S")
await sleep(1)
action_bar = pn.Row(
Spacer(width=20, sizing_mode="fixed"),
file_menu,
help_menu,
HSpacer(),
pn.pane.PNG(image, height=30, width=50, margin=0, sizing_mode="fixed", align="center"),
HSpacer(),
pn.panel(timer, width=75, styles={"color": "white"}, align="center"),
sizing_mode="stretch_width",
styles={"background": "var( --panel-primary-color )"},
)
action_bar.servable()
I added the timer
just for fun. Iām not sure I would add that in a real app.
from asyncio import sleep
from datetime import datetime
import panel as pn
from panel import HSpacer, Spacer
pn.extension()
image = "https://www.markdownguide.org/assets/images/tux.png"
file_menu = pn.widgets.MenuButton(
name="File", button_type="primary", items=["Save"], width=60, margin=0, align="center"
)
help_menu = pn.widgets.MenuButton(
name="Help", button_type="primary", items=["About"], width=60, margin=0, align="center"
)
async def timer():
while True:
yield datetime.now().strftime("%H:%M:%S")
await sleep(1)
action_bar = pn.Row(
Spacer(width=20, sizing_mode="fixed"),
file_menu,
help_menu,
HSpacer(),
pn.pane.PNG(image, height=30, width=50, margin=0, sizing_mode="fixed", align="center"),
HSpacer(),
pn.panel(timer, width=75, styles={"color": "white"}, align="center"),
sizing_mode="stretch_width",
styles={"background": "var( --panel-primary-color )"},
)
pn.template.VanillaTemplate(
title="Panel App with Header Content",
header=[action_bar],
logo = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/SCIPY_2.svg/512px-SCIPY_2.svg.png?20200904111722"
).servable()
Try playing around with this example.
hi @Marc , awesome. many thanks for your example how to customize the header panel.
regards
Hi @Marc thanks for the examples, Is it possible to center the template title?
Hi @Marc
I tried to use these ideas in order to create a Card header with a close button for the Card that is always right-justified. I did not succeed. Instead the close-button is justified so it is at the end of the header text, instead of the head of the entire row.
Could you tell me what I did wrong?
indicator = pn.Spacer(
width=20+12, # height=20,
sizing_mode='fixed',
align='center',
)
header_text = pn.widgets.StaticText(
value='New Analysis',
margin=(2, 0, 0, 0),
align=('start','center'),
)
close_button = pn.widgets.Button(
icon='x',
align=('end','center'),
)
editable_description = pn.widgets.TextInput(
placeholder='describe your analysis here',
disabled=False,
max_length=255,
sizing_mode='stretch_width',
)
card = pn.Card(
editable_description,
header=pn.Row(
indicator,
pn.Row(header_text,sizing_mode='stretch_width',align='center'),
close_button,
sizing_mode='stretch_width',
),
collapsed=False,
collapsible=True,
sizing_mode='stretch_width',
)
Thank you
GPN
You might need to edit the CSS
through styles
or stylesheets
@Marc published a workaround (to the latest issue, of right-justifying a close button) at