Hello,
In the request header, I will have stored information about the given user. And based on the user name, I would love to load data from the SQL server. I only know how to do that inside callback functions like update graph()
@app.callback(
Output(component_id="pie-chart", component_property="figure"),
[Input(component_id="dropdown", component_property="value"),
Input(component_id="url", component_property='href'), ],
prevent_initial_call=False,
)
def update_graph(name, href):
headers = flask.request.headers
print(headers)
kpi = load_data(user=headers['token'])
kpi = kpi[kpi["Level"].isin(name)]
fig = px.pie(kpi, names="Level", values="Count")
return fig
Can I somehow achieve the same but before callback? I mean if I Have app1.py file with the structure:
# app1.py
headers = flask.request.headers # here I get an error because at this stage flask server doesn't run yet.
kpi = load_data(user=headers['token'])
layout = [...]
@app.callback(
Output(component_id="pie-chart", component_property="figure"),
[Input(component_id="dropdown", component_property="value"),
Input(component_id="url", component_property='href'), ],
prevent_initial_call=False,
)
def update_graph(name, href):
kpi = kpi[kpi["Level"].isin(name)]
fig = px.pie(kpi, names="Level", values="Count")
return fig
Do you have any ideas on how to achieve my goal? Or can I load data only inside callback (if yes how then I can create dropdowns for layout if at layout createtion stage I don’t know yet options, values for dropdown)?