Skip to main content
Seasoned ⭐️
May 3, 2024
Question

Regarding current stlite limitations

  • May 3, 2024
  • 4 replies
  • 98 views

Using Stlite instead of a hosted Python runtime naturally limits the usability of Streamlit. I’m curious to what degree the following limitations have been considered and may be mitigated:

  • Query parameters: my app use query parameters to store the state and enable easy sharing of configurations. Will Streamlit on CDF ever support this?
  • Session state, persistence: How should things persisted when all is lost on a simple refresh? I don’t image writing state to CDF would work well.
  • Memory: I’ve worked with larger data sets of which only summaries are shown to the user. Could cognite functions work as a backend for this?
  • 3rd party libraries: Pydantic 2, Pola.rs &c. can’t compile to WASM (yet). I don’t image there is anything you can do about this, but I mention it because it is probably the most significant limitation and I’m curious as to whatever thoughts you have on it.

    4 replies

    Øystein Aspøy
    Seasoned ⭐️⭐️
    Seasoned ⭐️⭐️
    May 14, 2024

    @Armin Gharakhanloo Maybe this is something you can look into?

    Lars Moastuen
    Expert ⭐️⭐️⭐️⭐️
    Expert ⭐️⭐️⭐️⭐️
    May 15, 2024

    Hi @Boye Sjo and sorry for the delayed reply.

    I’ll go through your questions one by one:

    Query parameters

    This is actually possible to do today using st.query_params:

    import streamlit as st
    my_param = st.query_params['myCustomParameter']
    st.write(my_param)

    You will need to add the parameter to the URL. It might also be an idea to ensure that parameters hideCode=true and hideToolbar=true is set to hide code environment.

    Session state

    For session state we recommend st.session_state. This allows you to store per-session state, but it does not serialize across sessions. If you wish to store state between sessions you could look into https://pypi.org/project/extra-streamlit-components/ to store state across sessions using browser storage. I have not tried this myself but would be interested in hearing your experience if you try it out. 

    Memory

    I think using Cognite Functions as a way to offload heavy computation is an interesting approach and urge you to try :)

    3rd party libraries

    I agree that this is probably the most severe limitation of an in-browser implementation of Streamlit. We are very much aware of this and are discussing if/how to mitigate some of the pains. One thing we have discussed is the possibility to embed locally built “Python wheels” (*.whl) in the app to at least enable building wheels locally when they are not available.

    I hope this helps :) 

    Lars Moastuen (Software Engineer, Atlas AI)
    Dilini Fernando
    Expert ⭐️⭐️⭐️⭐️
    Expert ⭐️⭐️⭐️⭐️
    May 23, 2024

    Hi @Boye Sjo,

    Did the above help you?  

    Boye SjoAuthor
    Seasoned ⭐️
    May 23, 2024

    Somewhat. I can not get query parameters to work. They are accessible from 

    st.query_params

    but do not appear in the browser’s URL bar and do not persist when switching back from another page.

     

    As it stands, for the purposes of my current projects. I don’t think the native CDF hosting and user authentication will be worth the effort of migrating away from Pola.rs, query parameter states and server-wide caching in addition the risk of worse performance.