I stumbled upon Panel while building a Django app. Very excited to find that I could embed Panel’s extensive features/widgets/components etc through the bokeh-django package. That helped to reduce the effort on the UI side considerably. However, I hit a roadblock that hopefully I might get some hints on how to solve the problem.
Objective:
Button to reset a Tabulator to empty (meaning, no changes in columns, zero rows).
Sample Standalone Code:
import panel as pn
import pandas as pd
pn.extension()
pn.extension('tabulator') # tried with and without this
button = pn.widgets.Button(name="Reset Table",button_type='primary')
data = {
'row1': {'col1': 1, 'col2': 'a', 'col3': True},
'row2': {'col1': 2, 'col2': 'b', 'col3': False},
'row3': {'col1': 3, 'col2': 'c', 'col3': True}
}
df = pd.DataFrame.from_dict(data, orient='index')
table = pn.widgets.Tabulator(df,layout='fit_data_table')
def instantiate_table_edits(event,table):
if event:
print('clicked')
df_empty = pd.DataFrame(columns=['col1','col2','col3'])
table = pn.widgets.Tabulator(df_empty,layout='fit_data_table')
# table.value = df # no difference
return table
else:
return table
pn.panel(
pn.Column(
pn.pane.HTML('Please click to reset table'),
pn.Row(
button,
pn.bind(instantiate_table_edits, button,table=table),
),
# sizing_mode='stretch_width',
)
).servable()
# execute: panel serve app.py --dev
What happened:
In django, it does nothing and the console output (inspect mode) show an error “binary fragment but received text fragment” everytime the button is clicked (see screenshot below)
What I’ve tried:
Jupyter and standalone Panel app (code above) works. Although I did notice a change in the layout of the tabulator after resetting it using the code above, executed with panel server.
Browser inspect console output grumbled about “[Violation] Added non-passive event listener to a scroll”, but at least the button works.
How to reproduce the problem
(Un)Luckily, the sample app provided with bokeh-django also had the same problem when I added the button and tabulator, so hopefully it’s not the complexity or errors in my django environment. I’ve posted the issue on bokeh-django git site. The steps to reproduce the problem is outlined there in case if anyone is interested to reproduce in the django environment. (sorry for duplicate posting here but trying to reach a different audience to see what I’m missing)
Appreciate any ideas or directions I should take.