stlite icon indicating copy to clipboard operation
stlite copied to clipboard

store data permanently and be able to query it after a session ends in a Pyodide & stlite

Open OmarSa90 opened this issue 1 year ago • 9 comments

import streamlit as st import pandas as pd import micropip await micropip.install("openpyxl")

def main(): st.set_page_config( page_title="Omar's Reports", page_icon="👋", )

st.title("Driving Teacher's Dashboard")

try: students_df = pd.read_excel('files_omar/students.xlsx') st.dataframe(students_df.sort_index(ascending=False))

st.subheader("Add New Student")
with st.form(key='add_student_form'):
    name = st.text_input("Name")
    age = st.number_input("Age", min_value=0, max_value=150)
    grade = st.selectbox("Grade", ['A', 'B', 'C', 'D', 'F'])

    submit_button = st.form_submit_button("Add Student")

    if submit_button:
        # Create a new DataFrame with the input data
        new_student = pd.DataFrame({
            'Name': [name],
            'Age': [age],
            'Grade': [grade]
        })

        students_df = students_df.append(new_student, ignore_index=True)

        students_df.to_excel('files_omar/students.xlsx', index=False)


        st.success("New student added successfully!")

except FileNotFoundError: st.error("File not found: 'files_omar/students.xlsx'") except Exception as e: st.error(f"An error occurred: {str(e)}") if name == "main": main()

im unable to store data into the excel , hint, it can read from the excel, however not able to store

OmarSa90 avatar Mar 02 '24 06:03 OmarSa90

Unfortunately data persistence is not supported now.

Let us mark this issue as a feature request and track the progress here.

whitphx avatar Mar 14 '24 11:03 whitphx

Support different file systems on emscripten: https://emscripten.org/docs/api_reference/Filesystem-API.html#persistent-data

whitphx avatar Mar 14 '24 11:03 whitphx

@OmarSa90 Can you provide the details about your use case? For example, which deployment option/environment are you using? i.e. stlite sharing, desktop app bundler (@stlite/sharing), or self-hosting using @stlite/mountable

And, do you think it works if a special path like /mnt is provided as a persistent storage?

whitphx avatar Mar 14 '24 15:03 whitphx

@OmarSa90 Can you provide the details about your use case? For example, which deployment option/environment are you using? i.e. stlite sharing, desktop app bundler (@stlite/sharing), or self-hosting using @stlite/mountable

And, do you think it works if a special path like /mnt is provided as a persistent storage?

deskktop sharing, where would i make /mnt? { "name": "xxx", "version": "0.1.0", "main": "./build/electron/main.js", "scripts": { "dump": "dump-stlite-desktop-artifacts", "serve": "cross-env 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": "^0.48.0", "cross-env": "^7.0.3", "electron": "^28.2.1", "electron-builder": "^24.9.1" } }

OmarSa90 avatar Mar 28 '24 07:03 OmarSa90

Thanks!

Sorry it's confusing but this feature is not available. I wanted to know if such API design would work in your use case before I actually start developing it. Based on opinions including yours, I'm planning to make desktop apps able to mount the local FS into arbitrary paths but the home dir.

whitphx avatar Mar 28 '24 10:03 whitphx

Thanks!

Sorry it's confusing but this feature is not available. I wanted to know if such API design would work in your use case before I actually start developing it. Based on opinions including yours, I'm planning to make desktop apps able to mount the local FS into arbitrary paths but the home dir.

i remember that i managed to read(load) the excel file, however i could not write (save) data into in it i chose stlite since its too easy to build forms using streamlit, thus i would love to see how it would manage to save data into lcoal dir

OmarSa90 avatar Mar 28 '24 11:03 OmarSa90

Yes, I'm trying to develop something to do it.

i chose stlite since its too easy to build forms using streamlit, thus i would love to see how it would manage to save data into lcoal dir

That's good to know. So downloading the result files with st.download_button didn't meet your needs atm?

whitphx avatar Mar 28 '24 12:03 whitphx

Yes, I'm trying to develop something to do it.

i chose stlite since its too easy to build forms using streamlit, thus i would love to see how it would manage to save data into lcoal dir

That's good to know. So downloading the result files with st.download_button didn't meet your needs atm?

no, what i building is a form that saves the entered data into an excel file, the excel file servers as a database. i have tested to add some data to the excel file to see if Stlite would read(load) it and it did! however, it couldnt update the database (excel file) by any entered data by user since students_df = students_df.append(new_student, ignore_index=True)

    students_df.to_excel('files_omar/students.xlsx', index=False)

regarding downloading the data (via the new streamlit feature to the table;' save as csv') it does not store any data into the csv, always empty

OmarSa90 avatar Mar 29 '24 13:03 OmarSa90

I see. I think IDBFS works for your purpose. It's available with the latest ver. of stlite. If you want to sync files to the host OS, NODEFS is also an option.

whitphx avatar Apr 08 '24 13:04 whitphx