streamlit-rxdb-dataframe


Namestreamlit-rxdb-dataframe JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/voznik/ngx-odm
SummaryCustom streamlit component connecting local browser indexedDB database as RxDB collection as dataframe
upload_time2024-03-21 16:13:34
maintainerNone
docs_urlNone
authorvoznik
requires_python<4.0,>=3.10
licenseMIT
keywords streamlit indexeddb rxdb browser connection dataframe
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # streamlit-rxdb-dataframe

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

## Demo

[demo](https://st-rxdb-dataframe.streamlit.app/) - based on TodoMVC

![Example Screencast](https://github.com/voznik/ngx-odm/blob/master/packages/streamlit-rxdb-dataframe/screencast.gif?raw=true)

## Usage

### Provide JSONSchema

<details>
<summary>JSONSchema</summary>

```json
{
  "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
  }
}
```

</details>

### Provide Collection Config and use streamlit dataframe, data_editor or table

```python

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

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

### Build

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

### Publish

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

<!--
# TODO: Add form to construct RxQuery
    # query_container = st.container()
    # with query_container:
    #     to_filter_columns = st.multiselect(
    #         "Filter dataframe on",
    #         df.columns,
    #         key=f"{prefix}_multiselect",
    #     )
    #     filters: Dict[str, Any] = dict()
    #     for column in to_filter_columns:
    #         left, right = st.columns((1, 20))
    #         # Treat columns with < 10 unique values as categorical
    #         if is_categorical_dtype(df[column]) or df[column].nunique() < 10:
    #             left.write("↳")
    #             filters[column] = right.multiselect(
    #                 f"Values for {column}",
    #                 df[column].unique(),
    #                 default=list(df[column].unique()),
    #                 key=f"{prefix}_{column}",
    #             )
    #             df = df[df[column].isin(filters[column])]
    #         elif is_numeric_dtype(df[column]):
    #             left.write("↳")
    #             _min = float(df[column].min())
    #             _max = float(df[column].max())
    #             step = (_max - _min) / 100
    #             filters[column] = right.slider(
    #                 f"Values for {column}",
    #                 _min,
    #                 _max,
    #                 (_min, _max),
    #                 step=step,
    #                 key=f"{prefix}_{column}",
    #             )
    #             df = df[df[column].between(*filters[column])]
    #         elif is_datetime64_any_dtype(df[column]):
    #             left.write("↳")
    #             filters[column] = right.date_input(
    #                 f"Values for {column}",
    #                 value=(
    #                     df[column].min(),
    #                     df[column].max(),
    #                 ),
    #                 key=f"{prefix}_{column}",
    #             )
    #             if len(filters[column]) == 2:
    #                 filters[column] = tuple(map(pd.to_datetime, filters[column]))  # noqa: E501
    #                 start_date, end_date = filters[column]
    #                 df = df.loc[df[column].between(start_date, end_date)]
    #         else:
    #             left.write("↳")
    #             filters[column] = right.text_input(
    #                 f"Pattern in {column}",
    #                 key=f"{prefix}_{column}",
    #             )
    #             if filters[column]:
    #                 print(filters[column])
 -->

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/voznik/ngx-odm",
    "name": "streamlit-rxdb-dataframe",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "streamlit, indexedDB, RxDB, browser, connection, dataframe",
    "author": "voznik",
    "author_email": "mrvoznik@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c2/de/e1ec3adc4e99fd57d9fdb9bcf538c2570a46feff90b7ed981bde4e806e6d/streamlit_rxdb_dataframe-0.1.0.tar.gz",
    "platform": null,
    "description": "# streamlit-rxdb-dataframe\n\nCustom `streamlit` component connecting local browser `indexedDB` database as `RxDB` collection as `dataframe`\n\n## Demo\n\n[demo](https://st-rxdb-dataframe.streamlit.app/) - based on TodoMVC\n\n![Example Screencast](https://github.com/voznik/ngx-odm/blob/master/packages/streamlit-rxdb-dataframe/screencast.gif?raw=true)\n\n## Usage\n\n### Provide JSONSchema\n\n<details>\n<summary>JSONSchema</summary>\n\n```json\n{\n  \"definitions\": {},\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"object\",\n  \"title\": \"Todo\",\n  \"description\": \"Todo Schema\",\n  \"required\": [\"id\", \"title\", \"createdAt\"],\n  \"version\": 0,\n  \"properties\": {\n    \"id\": {\n      \"type\": \"string\",\n      \"format\": \"uuid\",\n      \"title\": \"Id\",\n      \"pattern\": \"^(.*)$\",\n      \"maxLength\": 36,\n      \"readOnly\": true\n    },\n    \"title\": {\n      \"type\": \"string\",\n      \"title\": \"Title\",\n      \"minLength\": 3\n    },\n    \"completed\": {\n      \"type\": \"boolean\",\n      \"title\": \"Done\"\n    },\n    \"createdAt\": {\n      \"type\": \"string\",\n      \"title\": \"Created Date\",\n      \"format\": \"date-time\",\n      \"readOnly\": true\n    },\n    \"last_modified\": {\n      \"type\": \"integer\",\n      \"format\": \"time\",\n      \"title\": \"Last Modified Date\"\n    }\n  },\n  \"__indexes\": [\"createdAt\"],\n  \"primaryKey\": \"id\",\n  \"attachments\": {\n    \"encrypted\": false\n  }\n}\n```\n\n</details>\n\n### Provide Collection Config and use streamlit dataframe, data_editor or table\n\n```python\n\ntodoSchema: Dict = json.load(open(os.path.join(data_dir, \"todo.schema.json\")))\n# initial_docs: List = json.load(open(os.path.join(data_dir, \"col.dump.json\")))[\"docs\"]\ncollection_config = {\n    \"name\": \"todo\",\n    \"schema\": todoSchema,  # to auto load schema from remote url pass None\n    \"localDocuments\": True,\n    \"options\": {\n        # 'schemaUrl': 'assets/data/todo.schema.json',\n        # \"initialDocs\": initial_docs,\n    },\n}\n\ndef on_change_dataframe(rxdb_state: RxDBSessionState):\n    print(\"RxDBDataframe component on_change call\")\n    print(\"collection.info()\", rxdb_state.info)\n    print(\"dataframe.head()\", rxdb_state.dataframe.head())\n\ndf = rxdb_dataframe(\n    collection_config,\n    query=None,\n    with_rev=False,\n    on_change=on_change_dataframe,\n)\nst.dataframe(\n    df,\n    use_container_width=True,\n    hide_index=True,\n    column_config=st.session_state[\"rxdb\"][\"column_config\"],\n    column_order=[\"title\", \"completed\", \"createdAt\"],\n)\n```\n\n## Run & Build\n\n### Run\n\n```bash\ncd packages/streamlit-rxdb-dataframe/\npoetry run streamlit run example.py\n```\n\n### Build\n\n```bash\npoetry build -o ../../dist/packages/streamlit-rxdb-dataframe\n```\n\n### Publish\n\n```bash\npoetry publish -r test-pypi --dist-dir ../../dist/packages/streamlit-rx\ndb-dataframe\n```\n\n<!--\n# TODO: Add form to construct RxQuery\n    # query_container = st.container()\n    # with query_container:\n    #     to_filter_columns = st.multiselect(\n    #         \"Filter dataframe on\",\n    #         df.columns,\n    #         key=f\"{prefix}_multiselect\",\n    #     )\n    #     filters: Dict[str, Any] = dict()\n    #     for column in to_filter_columns:\n    #         left, right = st.columns((1, 20))\n    #         # Treat columns with < 10 unique values as categorical\n    #         if is_categorical_dtype(df[column]) or df[column].nunique() < 10:\n    #             left.write(\"\u21b3\")\n    #             filters[column] = right.multiselect(\n    #                 f\"Values for {column}\",\n    #                 df[column].unique(),\n    #                 default=list(df[column].unique()),\n    #                 key=f\"{prefix}_{column}\",\n    #             )\n    #             df = df[df[column].isin(filters[column])]\n    #         elif is_numeric_dtype(df[column]):\n    #             left.write(\"\u21b3\")\n    #             _min = float(df[column].min())\n    #             _max = float(df[column].max())\n    #             step = (_max - _min) / 100\n    #             filters[column] = right.slider(\n    #                 f\"Values for {column}\",\n    #                 _min,\n    #                 _max,\n    #                 (_min, _max),\n    #                 step=step,\n    #                 key=f\"{prefix}_{column}\",\n    #             )\n    #             df = df[df[column].between(*filters[column])]\n    #         elif is_datetime64_any_dtype(df[column]):\n    #             left.write(\"\u21b3\")\n    #             filters[column] = right.date_input(\n    #                 f\"Values for {column}\",\n    #                 value=(\n    #                     df[column].min(),\n    #                     df[column].max(),\n    #                 ),\n    #                 key=f\"{prefix}_{column}\",\n    #             )\n    #             if len(filters[column]) == 2:\n    #                 filters[column] = tuple(map(pd.to_datetime, filters[column]))  # noqa: E501\n    #                 start_date, end_date = filters[column]\n    #                 df = df.loc[df[column].between(start_date, end_date)]\n    #         else:\n    #             left.write(\"\u21b3\")\n    #             filters[column] = right.text_input(\n    #                 f\"Pattern in {column}\",\n    #                 key=f\"{prefix}_{column}\",\n    #             )\n    #             if filters[column]:\n    #                 print(filters[column])\n -->\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Custom streamlit component connecting local browser indexedDB database as RxDB collection as dataframe",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/voznik/ngx-odm",
        "Repository": "https://github.com/voznik/ngx-odm"
    },
    "split_keywords": [
        "streamlit",
        " indexeddb",
        " rxdb",
        " browser",
        " connection",
        " dataframe"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "70bbe038f169247aad02cfab2d6ae5d94e7dcffd9f7494c934432e2c2ebe5ce9",
                "md5": "41127fc0eab1cf70aa97599594ccedce",
                "sha256": "0277802ed72dd7878e97d8166c1d725ab126a8677a66f4f72cf4ac20a61624be"
            },
            "downloads": -1,
            "filename": "streamlit_rxdb_dataframe-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "41127fc0eab1cf70aa97599594ccedce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 838760,
            "upload_time": "2024-03-21T16:13:30",
            "upload_time_iso_8601": "2024-03-21T16:13:30.350387Z",
            "url": "https://files.pythonhosted.org/packages/70/bb/e038f169247aad02cfab2d6ae5d94e7dcffd9f7494c934432e2c2ebe5ce9/streamlit_rxdb_dataframe-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c2dee1ec3adc4e99fd57d9fdb9bcf538c2570a46feff90b7ed981bde4e806e6d",
                "md5": "fb3f6b46481ac63f856aeb6f24e3f956",
                "sha256": "854106b58273574258f7804c248fced39a08016a2ccf94e8a7ec985eabaf8168"
            },
            "downloads": -1,
            "filename": "streamlit_rxdb_dataframe-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fb3f6b46481ac63f856aeb6f24e3f956",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 823982,
            "upload_time": "2024-03-21T16:13:34",
            "upload_time_iso_8601": "2024-03-21T16:13:34.029911Z",
            "url": "https://files.pythonhosted.org/packages/c2/de/e1ec3adc4e99fd57d9fdb9bcf538c2570a46feff90b7ed981bde4e806e6d/streamlit_rxdb_dataframe-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-21 16:13:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "voznik",
    "github_project": "ngx-odm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "streamlit-rxdb-dataframe"
}
        
Elapsed time: 0.28029s