Skip to main content

Custom streamlit component connecting local browser indexedDB database as RxDB collection as dataframe

Project description

streamlit-rxdb-dataframe

Custom streamlit component connecting local browser indexedDB database as RxDB collection as dataframe

Demo

demo - based on TodoMVC

Example Screencast

Usage

Provide JSONSchema

JSONSchema
{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "title": "Todo",
  "description": "Todo Schema",
  "required": ["id", "title", "createdAt"],
  "version": 0,
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "title": "Id",
      "pattern": "^(.*)$",
      "maxLength": 36,
      "readOnly": true
    },
    "title": {
      "type": "string",
      "title": "Title",
      "minLength": 3
    },
    "completed": {
      "type": "boolean",
      "title": "Done"
    },
    "createdAt": {
      "type": "string",
      "title": "Created Date",
      "format": "date-time",
      "readOnly": true
    },
    "last_modified": {
      "type": "integer",
      "format": "time",
      "title": "Last Modified Date"
    }
  },
  "__indexes": ["createdAt"],
  "primaryKey": "id",
  "attachments": {
    "encrypted": false
  }
}

Provide Collection Config and use streamlit dataframe, data_editor or table

todoSchema: Dict = json.load(open(os.path.join(data_dir, "todo.schema.json")))
# initial_docs: List = json.load(open(os.path.join(data_dir, "col.dump.json")))["docs"]
collection_config = {
    "name": "todo",
    "schema": todoSchema,  # to auto load schema from remote url pass None
    "localDocuments": True,
    "options": {
        # 'schemaUrl': 'assets/data/todo.schema.json',
        # "initialDocs": initial_docs,
    },
}

def on_change_dataframe(rxdb_state: RxDBSessionState):
    print("RxDBDataframe component on_change call")
    print("collection.info()", rxdb_state.info)
    print("dataframe.head()", rxdb_state.dataframe.head())

df = rxdb_dataframe(
    collection_config,
    query=None,
    with_rev=False,
    on_change=on_change_dataframe,
)
st.dataframe(
    df,
    use_container_width=True,
    hide_index=True,
    column_config=st.session_state["rxdb"]["column_config"],
    column_order=["title", "completed", "createdAt"],
)

Run & Build

Run

cd packages/streamlit-rxdb-dataframe/
poetry run streamlit run example.py

Build

poetry build -o ../../dist/packages/streamlit-rxdb-dataframe

Publish

poetry publish -r test-pypi --dist-dir ../../dist/packages/streamlit-rx
db-dataframe

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_rxdb_dataframe-0.1.0.tar.gz (824.0 kB view hashes)

Uploaded Source

Built Distribution

streamlit_rxdb_dataframe-0.1.0-py3-none-any.whl (838.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page