Randering error when main and sidebar are same

Hi
i get a randering issue when i my main area and sidebar area contain same widgets.

Plase see the example code here:

import panel as pn
pn.extension()
button1 = pn.widgets.Button(name ='1')
button2 = pn.widgets.Button(name ='2')
template = pn.template.MaterialTemplate(
    sidebar_width = 500,
)
template.main.append(button1)

template.sidebar.append(button2)
template.sidebar.append(button1)
template.show();

error code:


Any suggestion would be greatful.

Kind regards
Victor

Hi @CongTang,

Create a third button for main area and have it utilise the same callback as one of the buttons in the sidebar, so the button widget is different but the code run is the same that’s what I’d do here.

import panel as pn
pn.extension()
button1 = pn.widgets.Button(name ='1')
button2 = pn.widgets.Button(name ='2')
button3 = pn.widgets.Button(name ='3')

text = pn.widgets.TextInput(value='Ready button 1')
text1 = pn.widgets.TextInput(value='Ready button 2 & 3')

template = pn.template.MaterialTemplate(
    sidebar_width = 500,
)

def b(event):
    text.value = 'Button 1 Clicked {0} times'.format(button1.clicks)

def c(event):
    text1.value = 'Button 2&3 Combi Clicked {0} times'.format(button2.clicks + button3.clicks)

button1.on_click(b)
button2.on_click(c)
button3.on_click(c)


template.main.append(button3)

template.sidebar.append(button2)
template.sidebar.append(button1)

template.sidebar.append(text)
template.sidebar.append(text1)

template.show();

1 Like