✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Dash - Multi layout - loading first page again

im trying to develop a website for poc purpose, at first login page should prompt based on it, page2 layout have to show graph if login is correct. but in my case page 1 loads again which makes graph disappear after few seconds. below is code:

import dash
import dash_auth
import dash_core_components as dcc
from dash.dependencies import Input, Output, State, Event
import dash_html_components as html
import pandas as pd

app = dash.Dash(‘offline example’)

app.config.supress_callback_exceptions = True


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

index_page = html.Div(children=[
html.Form(children = [
html.Button(children=[‘loggin’],type=‘submit’, id=‘login_master’)
],id = ‘Signin’, hidden = False),

def page_load(pathname):
return page_1_layout

page_1_layout = html.Div(children=[
html.H3(“Please log in”, hidden=False, id=“page_header”),
# login form
html.P(children=["Username: ", dcc.Input(type=‘text’, id=‘username’, placeholder=‘username’)]),
html.P(children=["Password: ", dcc.Input(type=‘password’, id=‘password’, placeholder=‘password’)]),
html.Button(children=[‘Login’], type=‘submit’, id=‘login_button’)
], style={‘width’: ‘30%’, ‘margin’: ‘0 auto’}, id=“login_form”, hidden=False),
], style={‘display’: ‘block’, ‘text-align’: ‘center’, ‘padding’: 2}

page_2_layout = html.Div([
html.H3(“Please log in”, hidden=False, id=“page_graph”),
# login form
html.Form(children=[dcc.Graph(id=‘my-graph’, figure={‘data’: [{‘x’: [1, 2, 3], ‘y’: [4, 1, 2]}]})], id=“graph”),

@app.callback(Output(‘login_form’, ‘children’),
events=[Event(‘login_button’, ‘click’)],state=[State(‘username’, ‘value’), State(‘password’, ‘value’)])
def login(username,password):
if (username == password):
print(‘in if loop - click’)
return page_2_layout
#html.Div([dcc.Link(‘goto pg 2’,href=’/NSE DS/NSE DS/dashc.py’)])
#href=‘C:\Users\muthu\PycharmProjects\NSE DS\NSE DS\dashc.py’
return “Wrong username & password”

app.css.config.serve_locally = True
app.scripts.config.serve_locally = True

if name == ‘main’: