How to save parameter in web page

I am trying to run strikethrough application inside flask application.
I want to save the selected parameters. and when other people visit the website, they will see the parameters I have selected
I have found the GET/POST methods(How pass a parameter to DASH from FLASK)
for example:
link my web: http://172.16.10.234:8000/Sumary_Report/
after I select time it is: http://10.38.13.191:8000/Sumary_Report/?select_time=08092021
but i don’t know how to access dash .
Please help me …

If I understood your problem correctly, you want to be able to persist some data (parameters) across multiple users, is that right? You will need a database or equivalent to be able to do it, if this is what you are asking… one way to go is along the lines of example 4 here using Redis.

Oh no
I just want when I select a date then on my url link there will be an extra ‘/? select_time = 08092021’.
I will then send that link to someone else, and when they click on it, the site will be updated on September 8, 2021 without them having to reselect the date.

I have seen example here: dcc.Location refresh=False doesn't fire the callback for derived URL properties · Issue #925 · plotly/dash-core-components · GitHub
but when I apply it to my code it doesn’t work.It only update url , but don’t update chart.

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output,State
import plotly.express as px
import urllib
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv')

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Location(id='url', refresh=False),
    html.Div(id='content'),
    dcc.Graph(id='graph-with-slider'),

])

@app.callback(Output('content', 'children'), Input('url', 'href'))
def display_page(href):
    o = list(urllib.parse.urlparse(href))
    q = dict(urllib.parse.parse_qsl(o[4]))
    pathname = o[2]
    return html.Div([
        dcc.Slider(
        id='year-slider',
        min=df['year'].min(),
        max=df['year'].max(),
        value=df['year'].min(),
        marks={str(year): str(year) for year in df['year'].unique()},
        step=None
    ),
      
    ])  


@app.callback(
    Output('graph-with-slider', 'figure'),
    Input('year-slider', 'value'))
def update_figure(selected_year):
    filtered_df = df[df.year == selected_year]

    fig = px.scatter(filtered_df, x="gdpPercap", y="lifeExp",
                     size="pop", color="continent", hover_name="country",
                     log_x=True, size_max=55)

    fig.update_layout(transition_duration=500)

    return fig

@app.callback(
    Output('url', 'href'),
    Input('year-slider', 'value'),
    State('url', 'href'))
def update_pathname(site,href):
    if len(dash.callback_context.triggered) == 2:
        return dash.no_update

    o = urllib.parse.urlparse(href)
    o = o._replace(path='/')
    q = dict(urllib.parse.parse_qsl(o.query))
    q['site'] = site
    query_string = urllib.parse.urlencode(q)
    o = o._replace(query=query_string)
    return o.geturl()


if __name__ == '__main__':
    app.run_server(debug=False)

I fixed it here.

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output,State
import plotly.express as px
import urllib
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv')

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Location(id='url', refresh=False),

    html.Div(id='content'),
    dcc.Graph(id='graph-with-slider'),

])

@app.callback(Output('content', 'children'), Input('url', 'href'))
def display_page(href):
    o = list(urllib.parse.urlparse(href))
    q = dict(urllib.parse.parse_qsl(o[4]))
    pathname = o[2]

    if(q =={}):
        value = 1952
        value_ = 'Asia'
    else:
        value = int(q['site'])
        value_ = q['dum'] 
   
    
    return html.Div([
        dcc.Slider(
        id='year-slider',
        min=df['year'].min(),
        max=df['year'].max(),
        value= value,
        marks={str(year): str(year) for year in df['year'].unique()},
        step=None
    ), 
        
        
        dcc.Dropdown(id='yield_handler_select',
        options=[{'label':name, 'value':name} for name in df['continent'].unique()],
        value = value_,
        style=dict(width='40%',verticalAlign="middle"), ),
    ])  


@app.callback(
    Output('graph-with-slider', 'figure'),
    Input('year-slider', 'value'),
    Input('yield_handler_select','value'),
    State('url', 'href')
)
def update_figure(selected_year,continent,url):
    print(selected_year)
    filtered_df = df[df.year == selected_year]
    filtered_df = filtered_df[filtered_df.continent==continent]
    fig = px.scatter(filtered_df, x="gdpPercap", y="lifeExp",
                     size="pop", color="continent", hover_name="country",
                     log_x=True, size_max=55)

    fig.update_layout(transition_duration=500)

    return fig

@app.callback(
    Output('url', 'href'),
    Input('year-slider', 'value'),
    Input('yield_handler_select','value'),
    State('url', 'href'))
def update_pathname(site,dum,href):
    if len(dash.callback_context.triggered) == 2:
        return dash.no_update

    o = urllib.parse.urlparse(href)
    o = o._replace(path='/')
    q = dict(urllib.parse.parse_qsl(o.query))
    q['site'] = site
    q['dum']=dum
    query_string = urllib.parse.urlencode(q)
    o = o._replace(query=query_string)
    a= o.geturl()
    return o.geturl()


if __name__ == '__main__':
    app.run_server(debug=False)

Hello,

Thanks for update and quick reply, Looking for same issue and I found lots of information here, Really appreciate for help.

1 Like