Access Streamlit default color palette

Summary

I’m looking for a way to get Streamlit’s default color palette as a list of hex codes. My goal is to be able to color the background of rows in a table to match other plots in my app.

Details

The code below works using default plotly colors and by setting the theme of all my plots to theme=None to disable the default Streamlit theme. However, I’d like to recreate this using the default Streamlit color palette so that everything is more cohesive. Is there something I can replace plotly.colors.DEFAULT_PLOTLY_COLORS with below that would achieve the desired results?

Code snippet:

def get_color_map(camps):
    res = {}
    for i in range(len(camps)):
        res.update({camps[i]: plotly.colors.DEFAULT_PLOTLY_COLORS[i]})
    return res

def color_camps(val):
    color = cmap[val]
    return f'background-color: {color}'

cmap = get_color_map(st.session_state['campaigns'])
top_la = top_df.sort_values(by=['LA'], ascending=False).reset_index()
st.table(top_la[['Campaign', 'LA']].head(10).style.applymap(color_camps, subset=['Campaign']))

Debug info

  • Streamlit version: 1.16.0
  • Python version: 3.7.3

Requirements file

streamlit==1.16.0
google-auth==2.14.0
google-cloud-bigquery==3.3.5
db-dtypes==1.0.4
json5==0.8.4
jsonschema==3.0.1
pandas==1.3.5
plotly==5.11.0
plotly-express==0.4.0
jj-data-connector @ git+https://github.com/DataSolveProblems/jj_data_connector.git@ea9ccde1fee7ad382f5e145f5a0bfc7e26a2341c
gsheetsdb==0.1.13.1
millify==0.1.1
plotly-calplot==0.1.7

Links

Hey @Izzy_Bryant!

The Streamlit palette is not accessible from the native API yet (would be nice to have it! I agree with you) but you can find one that’s pretty close to it in here as part of one of the streamlit-extras components. If you were to install and use streamlit-extras, then you can just import the palette in your code, e.g. see this playground. If not, well you can copy paste that ST_COLOR_PALETTE variable in your code :wink:

Hope that helps