Saving a Bokeh Server Instance using .show() in the computer

Hi

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?)

Thanks and regards

Hi @SDSauron,

It looks great the teeth model.

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

import panel as pn

def func():
    return pn.Row('Hello World!')

pn.serve(func
, show=False) 

if you run pyinstaller --onefile exe_panel.py, it will generate the build and the dist folder where you can find the exe.

1 Like

You could also have a look at this Github repo that is a proof-of-concept turning a Panel app into a Desktok app using Toga.

1 Like

The idea looks awesome, does it still preserve the interactivity of the widgets?

Yes, the executable has akl thw packagws and python encapsulated. Depending on the packages you use, some problem can arise.

1 Like

Thanks, i’ll give it a try :smiley:

Almost done!!, but i got an strange error with the pyinstaller when importing the libraries.

fallo

Hi

Just would like to given people who having an issue to using pyinstaller for panel app:

please try this when you making app:
pyinstaller --onefile -F -w --copy-metadata bokeh --copy-metadata panel --collect-data xyzservices --collect-data pyecharts --clean panel_app.py

1 Like

Thanks @CongTang ! How’s your experience bundling a Panel app with PyInstaller? Does it work well?

Hi Maxi

It works well. Just need some work on solving -copy-metadata which is the issue coming with bokeh.

I was trying to share a panel app to people who don’t have python environment .

The panel to html function have limited function to access to local file system.

And i also don’t have a web deployment environment available, in this case, make panel app to a exe app is not bad idea.

1 Like

Hey :slight_smile: !

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

  1. Create a python env in cmd
    python -m venv panel_exe_env
  2. Active the env
    panel_exe>panel_exe_env\Scripts\activate.bat
  3. Install dependency by pip install:
    pip install panel pyinstaller
  4. 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()
  1. test it by:
    python app.py
  2. package it to exe by:
    pyinstaller --onefile --copy-metadata bokeh --collect-data xyzservices -F -w app.py
  3. 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.

Kind regadrs
Victor

1 Like