Python Forum
How to update component props every time when a Dash callback returns?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to update component props every time when a Dash callback returns?
#1
Hi All,

I am new to Dash. I’ve just started working on a dash component library in React. I have encountered a problem when trying to update a component prop from a Dash back-end callback. In order to illustrate my problem I suggest a simple example with a Button and a Div components. The Div needs to display the number of clicks.

I have the below implementation:
app.layout = html.Div(id='wrapper', children = [
    html.Button(id='click-btn', n_clicks = 0, children =  'Click' ),
    html.Div(id='click-result'),
])

@app.callback(Output('click-result', 'children'), [Input('click-btn', 'n_clicks')])
def click_btn_handler(n_clicks):
    if n_clicks != 0:
        time.sleep(5)
        return n_clicks
[Image: 8Kp4O.png]

I am clicking the button four times. Let’s say the interval between clicks is ~1 second. I can see that dash-renderer makes four requests to call my callback and then updates the Div’s children prop. As a result, the Div component is being updated only with the response from the last request - “children” is only being set to 4.

I suppose, probably for optimization purposes, dash-renderer ignores the previous three requests and waits for response only from the last one. However, I want my components to be updated with all responses that are returned from Dash callbacks. My components have functional purpose. They are supposed to execute some JavaScript logic and communicate with the back-end.

I would like to know, if there is a way to achieve this, or some workaround. I have searched to find whether this behavior is configurable for example, but I found nothing.

Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Update Date based on Time/String stevezemlicka 1 1,984 Jan-08-2021, 06:54 PM
Last Post: Gribouillis
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,626 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  create loop of subplot plotly dash without hardcode tonycat 0 3,874 Sep-23-2020, 08:40 AM
Last Post: tonycat
  update imhow in callback from pyaudio markB 0 2,311 May-28-2020, 06:01 PM
Last Post: markB
  Appending a list in a class from a callback function snizbatch 5 3,661 Sep-01-2019, 06:27 AM
Last Post: snizbatch
  I need help! How to package python code with other component into an exe file?? Wendy 4 2,812 Jul-15-2019, 01:29 PM
Last Post: snippsat
  Invalid archive error when attempting to install dash bootstrap components meaydemi 0 4,733 Jul-11-2019, 05:49 PM
Last Post: meaydemi
  Time in microseconds seems to update only every millisecond markB 3 2,360 Mar-16-2019, 05:56 PM
Last Post: markB
  Callback URL for twitter app Truman 5 5,347 Dec-10-2018, 10:45 PM
Last Post: nilamo
  how to use dataframe in dash? zhujp98 1 2,815 Jun-20-2018, 12:19 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020