Skip to main content

werkzeug router for streamlit

Project description

streamlit-router

Install

pip install streamlit-router

Example

    def index(router):
        st.text("fron page index")
        x = st.number_input("task id")
        if st.button("create task"):
            router.redirect(*router.build("create_task", {"x": x}))
        if st.button("cancel task"):
            router.redirect(*router.build("cancel_task", {"x": x}))
        if st.button("view task"):
            router.redirect(*router.build("view_task", {"x": x}))
        st.text("others on page index")

    # variable router auto inject if as first params
    def cancel_task(router, x):
        st.text(f"fron page cancel task x={x}")
        if st.button("back to index"):
            router.redirect(*router.build("index"))
        st.text("others on page cancel task")

   # variable router auto inject if as first params
    def create_task(x, router):
        st.text(f"fron page create task x={x}")
        if st.button("back to index"):
            router.redirect(*router.build("index"))
        st.text("others on page create task")

    router = StreamlitRouter()
    router.register(index, '/')
    router.register(cancel_task, "/tasks/<int:x>", methods=['DELETE'])
    router.register(create_task, "/tasks/<int:x>", methods=['POST'])

    # deco also works
    @router.map("/tasks/<int:x>")
    def view_task(x):
        st.text(f"fron page view task x={x}")
        if st.button("back to index 2"):
            router.redirect(*router.build("index"))
        st.text("others on page view task")

    router.serve()

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-router-0.0.1.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file streamlit-router-0.0.1.tar.gz.

File metadata

  • Download URL: streamlit-router-0.0.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.61.2 importlib-metadata/4.8.1 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for streamlit-router-0.0.1.tar.gz
Algorithm Hash digest
SHA256 59be971cf715e7251ef21598748fcb6a15cebe5be26d31350da6f94e625eae07
MD5 3439cf98e38708495e63d36261f029f4
BLAKE2b-256 07adbfeef8cc28f609bd9970f948675d5921d9d460866b486d038c5f4060b46b

See more details on using hashes here.

Supported by

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