Git Product home page Git Product logo

Comments (5)

jeffkayne avatar jeffkayne commented on September 26, 2024

The component returns None if the app is rerun without interacting with the component. I tried your code on my side and everything seems to work correctly to me?

from streamlit-feedback.

bpkapkar avatar bpkapkar commented on September 26, 2024

Thanks @jeffkayne for looking into it and answering it. In addition to it I am able to get return multiple value when user interacts with thumbs. one another challenge I am finding is , we are unable to return 2 values from the function given in below function and give key value error or even we reply user_response that's look like complete dictionary that doesn't work like key value function and gets key error

def _submit_feedback(user_response, emoji=None):
st.toast(f"Feedback submitted: {user_response}", icon=emoji)
print(user_response)
print(user_response["text"])
return user_response["score"], user_response["text"]

One more query how to identify the which thumbs has been clicked from series of thumbs that is available chat app so we can record the corresponding message to that thumbs reaction. How do we use feedback_key in this .

from streamlit-feedback.

jeffkayne avatar jeffkayne commented on September 26, 2024

the on_submit= funcion shouldn't return anything. It is a handler function that can do some action (e.g. save the response to a db) after submitting. To get the user_response, you should simply use the return variable of the component. In your example, that is the test variable

from streamlit-feedback.

bpkapkar avatar bpkapkar commented on September 26, 2024

Thanks @jeffkayne for looking into my query, to clarify more detail what I am trying to achieve. I am trying to record multiple data points example , score and text.
Below is the example when I am passing the function

def _submit_feedback(user_response, emoji=None):
st.toast(f"Feedback submitted: {user_response}", icon=emoji)

  • return user_response["score"]
    

I am able to get the response ๐Ÿ‘

this works fine.

  • At the same time when we are trying to get the two variable response back

def _submit_feedback(user_response, emoji=None):
st.toast(f"Feedback submitted: {user_response}", icon=emoji)
return user_response["score"], user_response["text"]
and modifying the function

reply1,reply2=streamlit_feedback(
feedback_type="thumbs",
optional_text_label="Please provide extra information",
on_submit=_submit_feedback,
key=feedback_key,
)

We get the error
image

reply1,reply2=streamlit_feedback(

TypeError: cannot unpack non-iterable NoneType object

  • Also tried another way where send back the complete dictionary but its not allowing to parse it

def _submit_feedback(user_response, emoji=None):
st.toast(f"Feedback submitted: {user_response}", icon=emoji)
return user_response

reply1=streamlit_feedback(
feedback_type="thumbs",
optional_text_label="Please provide extra information",
on_submit=_submit_feedback,
key=feedback_key,
)
print(reply1["score"])

We get the error print(reply1["score"])
TypeError: 'NoneType' object is not subscriptable

As I was looking to record the multiple data points I was facing this challenge as well . I found there might some code changes required in base library or I need to do correct things

from streamlit-feedback.

jeffkayne avatar jeffkayne commented on September 26, 2024

To store multiple data points, you need to reset your feedback component by using a dynamic key.

Here is some code that stores multiple feedback results in a session state variable:

import streamlit as st
from streamlit_feedback import streamlit_feedback

def handle_feedback(user_response):
    st.toast("โœ”๏ธ Feedback received!")


if "feedback" not in st.session_state:
    st.session_state.feedback = []

if "feedback_key" not in st.session_state:
    st.session_state.feedback_key = 0

if st.button("Refresh feedback component"):
    st.session_state.feedback_key += 1  # overwrite feedback component

result = streamlit_feedback(
    feedback_type="thumbs",
    align="flex-start",
    on_submit=handle_feedback,
    key=f"feedback_{st.session_state.feedback_key}",
)

if result:
    st.session_state.feedback.append(result)

# view session state
st.session_state.feedback

from streamlit-feedback.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.