Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

NavBar to display login vs logout button depending on logged in status

$
0
0

I’m trying to implement a simple NavBar that has the login/logout button - if user is not logged in - for the login button to appear - but once the user is logged it - for the bar to display the logout button

How can I get the layout adjusted dynamically?

#APP LAYOUT
app.layout = html.Div([
    dcc.Location(id='url', refresh=False),
    navbar_with_login,
    html.Div(id='page-content'),
])

#MAIN ROUTING
@app.callback(
        Output('page-content', 'children'),
        Input('url', 'pathname')
             )
def display_page(pathname):
    if pathname == '/':
        return layout_front_page
    if pathname == '/login':
        return login

#NAVBAR
navbar = dbc.NavbarSimple(
    children=[
        dbc.NavItem(dbc.NavLink("Login", href="/login")),
		#How to dynamically display login vs logout here>
            nav=True,
            in_navbar=True,
            label="More",
        ),
    ],
    brand="NavbarSimple",
    brand_href="#",
    color="primary",
    dark=True,
)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles