Dash-Access-Manager provides user access management for Dash.
Project description
Dash-Access-Manager
Dash-Access-Manager provides user access management for Dash.
It is based on Flask-Login to manage user session and on MongoEngine to use MongoDB databases.
Table of contents
Description
This is an implementation of an access management to be used in a dash app. It provides login, logout and sign up buttons that can be integrated in a layout of a dash app.
Installation
Install the extension with pip:
pip install dash-access-manager
Usage
Once installed, import the package in your app.py
.
import dash-access-manager as dam
app = dash.Dash(__name__)
server = app.server
Then, you have to set up the access manager. You need to change your_secret_key_here
as it not secret.
To do so, you can generate a secret key with the os
module by using os.urandom(12)
#Define a secret key that is required for Flask-Login to manage user session
server.secret_key = 'your_secret_key_here'
# Suppress errors for callbacks acting on layouts that are not displayed yet
app.config.suppress_callback_exceptions = True
# Initialize the acess manager
dam.init_access_manager(app)
After this you will define the layouts and callbacks of your dash app. Here is an simple example that can be used as it is.
app.layout = html.Div(children=[dcc.Location(id='url', refresh=False),
html.Div(id='root'),
html.Div(id='container')
])
def render_default_page(navbar_button=[], page_content=[html.H3("Login successfull")]):
return [
dbc.Navbar([
dbc.NavbarBrand("Navbar"),
] + navbar_button,
color="primary")
] + page_content
@app.callback(Output('root', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if dam.current_user.is_authenticated:
return render_default_page(dam.render_logout_button(), dam.render_logged_page())
else:
return render_default_page(dam.render_navbar_login() + dam.render_navbar_sign_up(), dam.render_login_page())
Finally, you need to connect the app with your MongoDB database before running your app.
You have to change DatabaseName
and DatabaseURL
with the ones you want to use.
If you want to use MongoDB you need to this change the host
parameter at mongodb+srv://username.password@cluster.url
where you have to replace username
, password
and cluster.url
by your information.
if __name__ == "__main__":
dam.connect(
db='DatabaseName',
host='DatabaseURL'
)
app.run_server()
You can use this file app.py to try it out.
Contributing
This project is under development so contributions are welcome to improve the code. Have a look at CONTRIBUTING.
Changelog
Take a look at CHANGELOG for more details.
License
Distributed under the MIT License. See LICENSE for more information.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dash_access_manager-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32a4dd408511bd78af23e19dc889b1f69e41e475c012a3d804bd18b3b4c8fcf6 |
|
MD5 | f850749c144d558b24d3ab70f5cee683 |
|
BLAKE2b-256 | a2efcb03ab1277024a664a5eb228edfdf1670a43036f4eaa5124de179edbb9e2 |
Hashes for dash_access_manager-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ada152042104632f234c7a5463e2ad52fe46fc2f343afea9e17a7391821401be |
|
MD5 | 2da7f7e2d8068d826f922c9eb6538b82 |
|
BLAKE2b-256 | 8a6c334a436c8816551b848245f289edfab538d104aeeb801f1328dc33dab0ab |