`st.write`/`st.json` render sets as strings
See original GitHub issueSummary
When I try to save a set in st.session_state and write it to the screen using st.write
, the set
is printed out as a string.
Steps to reproduce
Code snippet:
import streamlit as st
if ["list"] not in st.session_state:
st.session_state["list"] = []
if ["dict"] not in st.session_state:
st.session_state["dict"] = {}
if ["set"] not in st.session_state:
st.session_state["set"] = set()
st.write(st.session_state)
Expected behavior:
{
"list": [],
"set": set(),
"dict": {}
}
Actual behavior:
{
"list": [],
"set": "set()",
"dict": {}
}
Is this a regression?
No.
Debug info
- Streamlit version: 1.10
- Python version: 3.8
- Using virtualenv
- OS version: Ubuntu 20.04 on WSL2
- Browser version: Firefox 102
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
API Reference - Streamlit Docs
Streamlit makes it easy for you to visualize, mutate, and share data. The API reference is organized by activity type, like displaying data...
Read more >Rendering a JsonResult to a string in Razor - Stack Overflow
Create a string property and save the JSON as a string, then use JSON.parse in your View to convert it to an object....
Read more >Loading JSON data from Cloud Storage | BigQuery
Shows how to load JSON files from Cloud Storage into a new table, or append to, or overwrite a table. Shows how to...
Read more >19.3 Using the Object Model API - Oracle Help Center
keySet method returns a set of strings that contains the keys in the object, and the JsonObject.get(String name) method returns the value of...
Read more >Component Reference - Apache JMeter - User's Manual
If set, the JMeter sampler will check if the response is a redirect and follow it if so. ... GraphQL query (or mutation)...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Alternatively, we can create our own serialization instead of JSON, which allows two additional types to be transferred:
set
andtuple
.When it comes to displaying in UI, we can adopt a
pretty-format
format, that is, add a new label that describes the type.Before:
After:
This, however, will require us to make a fork of the library - react-json-view, which will support our data serialization format.
@sfc-gh-tszerszen +1 to this behavior. I think it’d probably be more desirable than nicely rendering it as a python set since, even though the types aren’t quite right, it’d be more useful for a user to be able to expand/collapse the list with existing functionality in
st.json
.I think this is a small decision that the product team would have to make the final call on, so CCing @jrieke to take a look at when he’s back from vacation 🌴