admin管理员组

文章数量:1289633

new to streamlit and have no experience with npm. I have created streamlit app and packaged it as an executable .exe following a tutorial . streamlit graphs/ functions (buttons, filters etc.) is working fine using package.json I created as follow,

{
  "name": "95L_schedule",
  "version": "0.4.0",
  "main": "./build/electron/main.js",
  "scripts": {
    "dump": "dump-stlite-desktop-artifacts",
    "serve": "cross-env NODE_ENV=production electron .",
    "servewindows": "electron .",
    "pack": "electron-builder --dir",
    "dist": "electron-builder",
    "postinstall": "electron-builder install-app-deps"
  },
  "build": {
    "files": ["build/**/*"],
    "directories": {
      "buildResources": "assets"
    },
    "win": {
    "target": "portable"
    }
  },
  "devDependencies": {
    "@stlite/desktop": "^0.76.0",
    "cross-env": "^7.0.3",
    "electron": "^33.0.1",
    "electron-builder": "^25.1.8"
  },
  "stlite": {
    "desktop": {
      "files": ["streamlit_app/app.py"],
      "entrypoint": "streamlit_app/app.py",
      "dependencies": ["numpy", "pandas", "plotly-express"]
    }
  }
}

new to streamlit and have no experience with npm. I have created streamlit app and packaged it as an executable .exe following a tutorial https://youtu.be/3wZ7GRbr91g?si=8FLBt3PsAxvEEzjo . streamlit graphs/ functions (buttons, filters etc.) is working fine using package.json I created as follow,

{
  "name": "95L_schedule",
  "version": "0.4.0",
  "main": "./build/electron/main.js",
  "scripts": {
    "dump": "dump-stlite-desktop-artifacts",
    "serve": "cross-env NODE_ENV=production electron .",
    "servewindows": "electron .",
    "pack": "electron-builder --dir",
    "dist": "electron-builder",
    "postinstall": "electron-builder install-app-deps"
  },
  "build": {
    "files": ["build/**/*"],
    "directories": {
      "buildResources": "assets"
    },
    "win": {
    "target": "portable"
    }
  },
  "devDependencies": {
    "@stlite/desktop": "^0.76.0",
    "cross-env": "^7.0.3",
    "electron": "^33.0.1",
    "electron-builder": "^25.1.8"
  },
  "stlite": {
    "desktop": {
      "files": ["streamlit_app/app.py"],
      "entrypoint": "streamlit_app/app.py",
      "dependencies": ["numpy", "pandas", "plotly-express"]
    }
  }
}

And then in the windows command prompt

npm install
npm run dump numpy pandas matplotlib
npm run dist

through my streamlit code, I want to be able to write files (save matplotlib figures) on the local drive where this executable is running.

I tried accessing the current working directory with something like below but it does not work, I am assuming executable is running in some sort of npm shell and not on windows itself.

 with st.form(key='create_prints'):
        submit_button = st.form_submit_button(label='create printable files')

    if submit_button:
        base_path = os.getcwd() + "/" + assign['start_timestamp'].min().strftime('%Y%m%d') + "/"
        os.makedirs(base_path + "machines/", exist_ok=True)

How should I go about it? thank you!

Share Improve this question asked Feb 20 at 19:42 amenamen 451 silver badge12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

According to Stlite's README, you have to add this to your json file in the "desktop" object :

"nodeJsWorker": true,
"nodefsMountpoints": {
 "/mnt": "."
}

Here, the key "/mnt" (or any name you want) is used as a path in the virtual file sytem. The value, "." in this case is the actual directory in the user's file system. So in your app, when you are doing something using a path starting with /mnt, it will map to the real directory on the user's computer. You can't just use get directories' in their machine by using os since the app is using a virtual file system.

本文标签: