question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set trigger values for custom button components

See original GitHub issue

Problem

As far as I know, it is not possible to set a one-time value using JavaScript Component API. The only method available is Streamlit.setComponentValue().

Thus, it is not possible to implement custom buttons easily.

Solution

In native widgets, setting a one-time value is done with setTriggerValue. It’d be great to have this function for components.

Additional context

This issue was already discussed here: https://discuss.streamlit.io/t/button-using-custom-component/7536. In this topic, I’ve provided a temporary solution which triggers two reruns after a button click.

Another temporary solution would be to rely on query parameters. But I haven’t tested this yet.


Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

If you’d like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
okldcommented, Oct 18, 2021

Another temporary solution using st.session_state:

import streamlit as st

def return_value_once():
    # Let's assume that slider is a custom component that returns the same value everytime
    new_value = st.slider("My component value", 1, 10)

    if "old_value" not in st.session_state or new_value != st.session_state.old_value:
        st.session_state.old_value = new_value
        return new_value

    return None

st.title("Return value only if changed")
st.write("Here is my value:", return_value_once())
0reactions
PablocFonsecacommented, Oct 18, 2021

Pushing this one up. I just got in the same situation of @andfanilo and @okld. Needed to implemnt a custom button like component and no other way besides setComponentValue and block component return in python.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In React how can I trigger a custom button's click event ...
I've created a custom button component which styles the default Material UI button and also uses redux. The render() function of my button...
Read more >
Button using Custom Component
Sure, this is actually what the Streamlit Component template consists of :slight_smile: ... Set trigger values for custom button components.
Read more >
Tutorial 5: Creating Custom Triggers and Actions
Tutorial 5: Creating Custom Triggers and Actions. With TouchGFX Designer it is possible to define your own interaction components with custom triggers and ......
Read more >
13 Trigger Actions in Dynamic Components
Define Behavior for Components in Layouts · Open the Layout's Actions tab. · Create the variables you might want to use in your...
Read more >
Flow Screen Input Component: Screen Button
Setting the attribute enables a flow to remember the value. The flow stores the value automatically. If you store values manually, store the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found