Make an standalone executable file for windows

Hi,
I used dash and python to make an interactive dashboard for data analyses.
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd

The result is showed under http://127.0.0.1:8050/ whilst the code in spyder is running.
Is there any possibility to make an standalone executable file for windows so that one can use it locally without any knowledge in python or dash?
Simply, the user clicks just on the file and it runs locally.

1 Like

Hi @nima,
That’s a good question, it is a problem I will be trying to solve in a few days to also ship a prototype of my dashboard done with Dash.
The first thing coming to my minds is for you to take a look at Pyinstaller. Its purpose is exactly that, bundling python projects into executables. You will then only have to open a browser and go to localhost:8050. This might even be feasible through code, with a bit of research
Let me know how it goes for you if you try that way!

Otherwise you could also look into deployment possibilities.

Finally, I didn’t get what you meant by this:

:thinking:

1 Like

thanks a lot,
that ist just part of the code. To be honest I forgot why I wrote this part :grinning:

Hey @nima, did you try/succeed in making an executable with PyInstaller?

Hey, @nima or @lamourj hopefully you were able to create this executable?

I am interested in this as well, I am going to give it a try this week and post back

I went this route for a prototype and was able to get a standalone executable working. I was running into issues with the files in the assets folder. A work-around I found was to manually tell pyinstaller to include them in a folder called “assets” in the build. You can do this by using an --add-data command for each item in the assets.

pyinstaller --add-data “assets/favicon.ico;assets” --add-data “assets/custom_scripts.js;assets” dash_app.py

you can also use the .spec file to achieve this, more details are in the pyinstaller docs.

3 Likes

@DandsomeHan I have the same issue as you with including the assets, but your solution doesn’t work for --onefile option?

I can read the working directory of the exe file into a string in the python code and pass it to assets_url_path(), but somehow dash doesn’t pick up the asset files from there.

I have apost on stackoverflow about this, just in case anyone ever runs into the same issue and it happens to get solved: https://stackoverflow.com/questions/55596932/how-can-i-include-assets-of-a-dash-app-into-an-exe-file-created-with-pyinstaller

Anyone has step-by-step instructions to create a standalone exe from dash app.

After several errors I made it following this Topic:

@luquezsantiago

I also tried to follow this guide, but unfortunately I get an error about the options = options in the setup.py.
Is there any chance you could help me with a step by step guide what you did to achieve a working exe?

Hi, I will try later to send you a Step by Step. For now, I share you and example of what I did, and It works.
I remember I had some problems with some files:
–> .dll from windows not found: The solution was to look for the file and incorporate it to the package.

-Question: why not to deploy it? I found it so much easier, and if you use heroku its free.
Also remember every time you want to make an improve, you will have to remake que .exe file.

Unfortunately I can’t deploy it on a server in this particular case. Thank you for the quick update!

@luquezsantiago It works! Or atleast, no errors compiling anymore. And when I click the .exe I don’t have any errors anymore. I needed to create a separate virtual environment. I think some packages might have conflicted with each other in my main environment.

However when I click the .exe file now, nothing really happens.
Separately my codes works. I think it might be because I import csv files. Do you maybe know what the correct way is of doing this? Do I need to add something to the setup.py?

Ok good, its a big step!

  1. Yes, create the venv. Make sure you requirements.txt is exactly what you need.
  2. If you want to open the browser automatically, you can use “webbrowser” as I did in the example.
  3. I dont know exactly what you did, but you should import all de datasets in the package.
  4. I used the option .msi (instead of .exe)

Just to be clear, the requirements.txt needs to include all the different packages that are included in the dashboard app right? Is this required in order to make it run correctly?

It crashes when I add import pandas as pd in my script, so it should be something related with the packages.
I thought this shouldnt be a problem since I add ’pandas’ to the ’includes’ part of the options[’build_exe’]

EDIT: I think it might crash due to dll’s not begin included. Do you @luquezsantiago by any chance know which dll’s you included?

Hello Everyone,

I’m facing the issue using auto-py-to-exe compile to .exe and also pyinstaller, i have tried both options single file and single directory with and without console. I’m not able to have the web app run on port 80 like i do in spyder IDE. Is there any trick with the webserver maybe ?? to my understanding the development web server of dash is able to run through the virtual environment, but is not the same running on bare OS (windows). Anyone with experience on this ?