Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dash Python App Button for action and refresh the page

Tags:

Need to have a callback function in Dash App for performing some action and then refreshing the page, only page reload could be achieved using HTML A tag.

html.A(html.Button('Refresh Data'),href='/')

Required:

app.layout = html.Div([html.Button(id="refresh")])

@app.callback(Output('???', '???'),
          [Input('refresh', 'n_clicks')])
def refresh(n):
## Perform some action ##
## call python function API ##
## Finally Refresh the Page ##
 ?
return ?
like image 210
hagarwal Avatar asked May 10 '20 17:05

hagarwal


People also ask

What is dash in Python used for?

Dash is an open source framework for building data visualization interfaces. Released in 2017 as a Python library, it's grown to include implementations for R and Julia. Dash helps data scientists build analytical web applications without requiring advanced web development knowledge.

What is a callback function dash?

Whenever an input property changes, the function that the callback decorator wraps will get called automatically. Dash provides this callback function with the new value of the input property as its argument, and Dash updates the property of the output component with whatever was returned by the function.

What is Dash callback context?

Using dash. callback_context , you can determine which component/property pairs triggered a callback. Below is a summary of properties of dash. callback_context outlining the basics of when to use them. For more detail and examples see Determining Which Callback Input Changed.

What is Python Plotly dash?

Dash is a python framework created by plotly for creating interactive web applications. Dash is written on the top of Flask, Plotly. js and React. js. With Dash, you don't have to learn HTML, CSS and Javascript in order to create interactive dashboards, you only need python.


1 Answers

I guess this is the proper way to do it:

add this to your layout:

dcc.Location(id='url', refresh=True),

callback:

@app.callback(
    Output("url", "href"),
    Input("App-logo", "n_clicks"),
    prevent_initial_call=True,
)
def reload_data(_):
    return "/"
like image 63
HeyMan Avatar answered Oct 05 '22 00:10

HeyMan