I have a Django endpoint that has the following structure:
The value of the url paramter id is used to acces a sql database to obtain the x,y values to plot a scatterplot. I have read several solutions such as this one (Pass initial argument from django to django dash app · Issue #279 · GibbsConsulting/django-plotly-dash · GitHub) that uses initial_arguments. The thing is that when reading this variable on DjangoDash, this is actually not used outside the callback statements, so I am not sure if I can reuse this solution. My current code is as follows:
views.py
:
id = request.GET.get('id', "abc")
context = {}
context['dash_context'] = {'target_id': {'id':id}}
return render(request, 'plot.html', context)
plot.html
{% load plotly_dash %}
{%plotly_app name="Plot" ratio=1 initial_arguments=dash_context %}
plot.py
app = DjangoDash('Plot')
# ----> TODO: read id variable from initial_arguments <----
csv_file = os.path.join(constants.PROCESSED_FILES_PATH, f"plots/{id}.csv")
df = pd.read_csv(csv_file)
fig = px.scatter(df, x='x_vals', y="y_vals", title='MyTitle')
app.layout = html.Div(children=[
dcc.Graph(
id='myplot',
figure=fig
),
])
Therefore, my question is, given the code above, is it possible to read in that Python context the id variable passed from the view to de DjangoDash app?