Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron app bundler #301

Closed
whitphx opened this issue Sep 30, 2022 · 13 comments
Closed

Electron app bundler #301

whitphx opened this issue Sep 30, 2022 · 13 comments

Comments

@whitphx
Copy link
Owner

whitphx commented Sep 30, 2022

Rel #69

  1. Publish @stlite/desktop with its ./build directory in which the built JS app code is included. Publish @stlite/desktop NPM package #314
  2. Publish @stlite/stlite-kernel with the wheels that is needed in the following bundling steps. feature/bundle kernel package #302

Then, the Streamlit app creator who wants to bundle the app with Electron will do the following steps.

  1. Create an electron app project that only contains package.json looking like below. It is extracted from the packge.json in @stlite/desktop only with the electron-builder configs and @stlite/stlite-kernel dependency, from which the wheels are loaded at the bundle time.
{
  "name": "xxx",
  "version": "xxx",
  "main": "./build/electron/main.js",
  "dependencies": {},
  "scripts": {
    "pack": "electron-builder --dir",
    "dist": "electron-builder",
    "postinstall": "electron-builder install-app-deps"
  },
  "build": {
    "appId": "your.id",
    "mac": {
      "category": "your.app.category.type"
    },
    "productName": "xxx",
    "extends": null,
    "files": [
      "build/**/*"
    ],
    "directories": {
      "buildResources": "assets"
    }
  },
  "devDependencies": {
    "electron": "20.2.0",
    "electron-builder": "^23.3.3"
  }
}
  1. Copy the ./build directory from @stlite/desktop.
  2. Run ./bin/dump_snapshot.ts from @stlite/desktop (this scripts needs the wheel files from @stlite/stlite-kernel).
  3. Run yarn dist.

In the future, creating the project with package.json above can be automated like yarn create.

@whitphx
Copy link
Owner Author

whitphx commented Oct 5, 2022

At this point, use #322 (comment)

@whitphx
Copy link
Owner Author

whitphx commented Oct 5, 2022

Current version of the stlite desktop app development

[Updated: use @stlite/desktop-cli instead of @stlite/desktop]

Repo: https://github.com/whitphx/stlite-desktop-example
Sample apps: https://github.com/whitphx/stlite-desktop-example/releases/tag/v0.2.0

  1. Create a new NPM project with the following package.json. Edit the name field.
{
  "name": "xxx",
  "version": "0.1.0",
  "main": "./build/electron/main.js",
  "scripts": {
    "dump": "dump-stlite-desktop-artifacts",
    "serve": "NODE_ENV=\"production\" electron .",
    "pack": "electron-builder --dir",
    "dist": "electron-builder",
    "postinstall": "electron-builder install-app-deps"
  },
  "build": {
    "files": [
      "build/**/*"
    ],
    "directories": {
      "buildResources": "assets"
    }
  },
  "devDependencies": {
    "@stlite/desktop-cli": "^0.12.0",
    "electron": "20.2.0",
    "electron-builder": "^23.3.3"
  }
}
  1. Run npm install or yarn install.
  2. Create streamlit_app directory.
    • Any directory name can be used here.
  3. Create streamlit_app/streamlit_app.py.
    • Change the directory name if you used a different name in the previous step.
  4. Write your Streamlit app code in streamlit_app/streamlit_app.py.
  5. Optionally, you can add more contents in the directory, including pages/*.py for MPA, any data files, and so on.
  6. Run yarn dump streamlit_app. If some packages are needed, use -r option like yarn dump streamlit_app -r <PackageName1> ... <PackageNameN>.
    • This command creates ./build directory. It includes
      • The stlite bare app files.
      • streamlit_app directory copied from the one you created in the previous steps.
      • site-packages-snapshot.tar.gz that includes the installed package files.
  7. Run yarn serve for preview. Run yarn dist for packaging.
    • electron-builder is used (see the "scripts" field in the package.json) and it simply bundles the ./build directory created in the step above. If you want to customize the built app, e.g., setting the icon, follow its instruction.

@whitphx
Copy link
Owner Author

whitphx commented Oct 5, 2022

TODO:

@blackary
Copy link
Contributor

blackary commented Oct 5, 2022

FYI, I get this when trying to open the sample app dmg on my M1 mac
image

@blackary
Copy link
Contributor

blackary commented Oct 5, 2022

When I built my own locally, it worked on the first run, but when I closed it (with the x) and opened it again, I got this error
image

@whitphx
Copy link
Owner Author

whitphx commented Oct 6, 2022

@blackary I don't know why it did not work (it was built on my local machine and uploaded manually to the GitHub release page).
However I set up a different build and release flow on the CI/CD and created new files: https://github.com/whitphx/stlite-desktop-example/releases/tag/v0.2.0

@blackary
Copy link
Contributor

blackary commented Oct 6, 2022

@whitphx Thanks! I installed the new dmg, and it installed fine, but when it opens on my machine, it shows the loading bar briefly, then goes to a blank page
image

@mkisono
Copy link

mkisono commented Oct 7, 2022

@whitphx

Current version of the stlite desktop app development

I followed the steps and it's working fine on my mac.

When I run the following code as strreamlit_app.py, the progress bar didn't actually "progress". It just showed the end result. Is this by design or limitation?

import time
import streamlit as st

my_bar = st.progress(0)

for percent_complete in range(100):
    time.sleep(0.1)
    my_bar.progress(percent_complete + 1)

@whitphx
Copy link
Owner Author

whitphx commented Oct 7, 2022

@blackary Thanks,
Can you please tell if there are any errors on the console by opening the dev console from the menu as below?

View_と_Menubar_と_streamlit_app_·_Streamlit

@whitphx
Copy link
Owner Author

whitphx commented Oct 7, 2022

@mkisono Thank you for trying it out, and

it's working fine on my mac.

it was a great report :)


It just showed the end result. Is this by design or limitation?

it looks like the known issue as #34 (comment) ; time.sleep() does no-op on Pyodide runtime (pyodide/pyodide#2354). It is a limitation of the Wasm-ported Python runtime which may be resolved in the future.
#64 may also be the related topic.

@blackary
Copy link
Contributor

blackary commented Oct 7, 2022

@blackary Thanks,
Can you please tell if there are any errors on the console by opening the dev console from the menu as below?

@whitphx I gave that a try, and now am unable to reproduce the blank page I was getting 🤷 . So, the dmg you made is working for me now.

(Though, I still get that same error if I close and reopen the app)

@whitphx
Copy link
Owner Author

whitphx commented Oct 11, 2022

I will close this issue.
The next TODOs have been created as separate issues.

@whitphx whitphx closed this as completed Oct 11, 2022
@weissenbacherpwc
Copy link

is this still working or is there an update on how to convert a streamlit app to .exe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants