After moths of working in an App using Bokeh and Panel y a Jupyter Notebook my final step is to move all the code done in Jupyter Lab to an app or Browser App in which the user could navigate through a Dashboard.
The code consists on a Panel+Plotly+Bokeh app with many interactive actions which activate functions made in Python. I tried using “aplication.show()” (being aplication the variable of the panel with which the user interacts) and i get a new tab in the browser that works fine, just as if it was running in the notebook.
It looks awesome!! and i’ve read that all is running appart from Jupyter in a Bokeh Server. Is there any way to save this app into a local file and when the user double clicks on the file it is executed (for example, it opens in the browser and displays the app with all the interactive options?)
You can check pyinstaller. There is more info in the following links
Basically you need to add a hook to py installer. For that you need to add a file hook-panel.py to the hooks folder located in the Pyinstaller folder in the site packages of your python environment (What is python's site-packages directory? - Stack Overflow) with the following content
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('panel', include_py_files=True) + \
collect_data_files('pyviz_comms', include_py_files=True) + \
collect_data_files('bokeh') # See https://github.com/pyinstaller/pyinstaller/pull/4746
and have your panel application (exe_panel.py) like this
Nice to hear it actually works well. If you’ve managed to document the process, even in the form of notes, it’d be great to share it with the community somehow. We could start a new topic in the Showcase category, and later document that in How-to — Panel v1.1.0.
Sure, Just a quick note about using pyinstaller in panel
Create a python env in cmd python -m venv panel_exe_env
Active the env panel_exe>panel_exe_env\Scripts\activate.bat
Install dependency by pip install: pip install panel pyinstaller
Find a panel Example:
import panel as pn
pn.extension()
styles = {
'background-color': '#F6F6F6', 'border': '2px solid black',
'border-radius': '5px', 'padding': '10px'
}
html_pane = pn.pane.HTML("""
<h1>This is an HTML pane</h1>
<code>
x = 5;<br>
y = 6;<br>
z = x + y;
</code>
<br>
<br>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
""", styles=styles)
pn.Column(html_pane).show()
test it by: python app.py
package it to exe by: pyinstaller --onefile --copy-metadata bokeh --collect-data xyzservices -F -w app.py
if you get any issue with page not find in you exe, you need to add --copy-metadata < package> to the pyinstaller command, if you get any issue with missing data file in you exe, you need add–collect-data .
Hopefully this could be help.
I will find sometime later to batter to docuement it.