Streamlit Feedback Component
Streamlit-feedback is a Streamlit component that allows developers to easily collect structured or free-form user feedback, such as thumbs up/down, emoji faces, or text comments, directly within their Streamlit applications. It is currently at version 0.1.4 and receives updates for compatibility with new Streamlit versions and feature enhancements, maintaining an active development status.
Common errors
-
streamlit.errors.StreamlitAPIException: st.text_input() was called with a key='...' that is already in use. Each widget must have a unique key.
cause You have multiple `st_feedback` components (or other Streamlit widgets) on the same page without unique `key` arguments, causing a conflict.fixAssign a unique string to the `key` parameter for each `st_feedback` call, e.g., `st_feedback(..., key="feedback_section_1")`. -
ModuleNotFoundError: No module named 'streamlit_feedback'
cause The `streamlit-feedback` library is not installed in your current Python environment.fixInstall the library using pip: `pip install streamlit-feedback`. -
My feedback component doesn't appear in my Streamlit app when I run it.
cause This often occurs if the Streamlit app is not being run correctly, if the component call is inside an un-met conditional block, or if there's an earlier error preventing rendering. It also might not appear until a certain interaction happens.fixEnsure your script is launched with `streamlit run your_script_name.py`. Verify that the `st_feedback` call is executed unconditionally, or that its conditional logic is met. Check the terminal for any Python or Streamlit-specific errors that might be preventing rendering.
Warnings
- gotcha The `st_feedback` component must be executed within a Streamlit application (`streamlit run your_app.py`). Running the script as a standalone Python file will not display the UI component and may result in errors related to missing Streamlit context.
- gotcha When using `st_feedback` multiple times on the same Streamlit page, each instance *must* be assigned a unique `key` parameter. Failing to do so will cause a `StreamlitAPIException` due to key conflicts.
- gotcha The structure of the dictionary returned by `st_feedback` when feedback is submitted varies based on the `feedback_type` (e.g., 'thumbs', 'faces', 'text'). Developers must inspect the `feedback_type` field and conditionally access fields like `score` or `text`.
Install
-
pip install streamlit-feedback
Imports
- st_feedback
from streamlit_feedback import st_feedback
Quickstart
import streamlit as st
from streamlit_feedback import st_feedback
st.set_page_config(layout="wide")
st.header("User Feedback Example")
# Basic thumbs up/down feedback
feedback_thumbs = st_feedback(
feedback_type="thumbs",
optional_text_label="Tell us more (optional):"
)
if feedback_thumbs:
st.success(f"Thumbs Feedback received: {feedback_thumbs}")
# In a real application, you would store this feedback (e.g., to a database).
else:
st.info("Please provide your thumbs feedback.")
st.markdown("--- ")
# Faces feedback with a custom key
st.subheader("Rate your experience")
feedback_faces = st_feedback(
feedback_type="faces",
feedback_options=["๐ Excellent", "๐ Good", "๐ Neutral", "๐ Poor", "๐ Very Poor"],
key="experience_feedback" # Unique key is crucial for multiple widgets
)
if feedback_faces:
st.success(f"Faces Feedback received: {feedback_faces}")
else:
st.info("Please rate your experience.")
st.caption("To run this app, save it as `app.py` and execute: `streamlit run app.py`")