st.feedback
Display a feedback widget.
A feedback widget is an icon-based button group available in three styles, as described in options. It is commonly used in chat and AI apps to allow users to rate responses.
| Function signature[source] | |
|---|---|
st.feedback(options="thumbs", *, key=None, default=None, disabled=False, on_change=None, args=None, kwargs=None, width="content") | |
| Parameters | |
options ("thumbs", "faces", or "stars") | The feedback options displayed to the user. options can be one of the following:
|
key (str, int, or None) | An optional string or integer to use as the unique key for the widget. If this is None (default), a key will be generated for the widget based on the values of the other parameters. No two widgets may have the same key. Assigning a key stabilizes the widget's identity and preserves its state across reruns even when other parameters change. Note Changing options resets the widget even when a key is provided. A key lets you read or update the widget's value via st.session_state[key]. For more details, see Widget behavior. Additionally, if key is provided, it will be used as a CSS class name prefixed with st-key-. |
default (int or None) | Default feedback value. This must be consistent with the feedback type in options:
|
disabled (bool) | An optional boolean that disables the feedback widget if set to True. The default is False. |
on_change (callable) | An optional callback invoked when this feedback widget's value changes. |
args (list or tuple) | An optional list or tuple of args to pass to the callback. |
kwargs (dict) | An optional dict of kwargs to pass to the callback. |
width ("content", "stretch", or int) | The width of the feedback widget. This can be one of the following:
|
| Returns | |
(int or None) | An integer indicating the user's selection, where 0 is the lowest feedback. Higher values indicate more positive feedback. If no option was selected, the widget returns None.
|
Examples
Display a feedback widget with stars, and show the selected sentiment:
import streamlit as st
sentiment_mapping = ["one", "two", "three", "four", "five"]
selected = st.feedback("stars")
if selected is not None:
st.markdown(f"You selected {sentiment_mapping[selected]} star(s).")
Display a feedback widget with thumbs, and show the selected sentiment:
import streamlit as st
sentiment_mapping = [":material/thumb_down:", ":material/thumb_up:"]
selected = st.feedback("thumbs")
if selected is not None:
st.markdown(f"You selected: {sentiment_mapping[selected]}")
Tip
Want a new st.feedback feature or found a bug? Browse open issues and react with a 👍 on the initial post of the ones that matter to you. Your votes help us prioritize what to work on next.
Still have questions?
Our forums are full of helpful information and Streamlit experts.