Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to query database and pass it to the plotly_app #498

Open
jsulopzs opened this issue May 3, 2024 · 3 comments
Open

How to query database and pass it to the plotly_app #498

jsulopzs opened this issue May 3, 2024 · 3 comments

Comments

@jsulopzs
Copy link

jsulopzs commented May 3, 2024

Goal

I am trying to render a Dash app through a template that takes input from the view after calling the URL (that's how Django works).

The main problem I face is how to pass data through this logic.

Context

  • The database is a Redshift instance whose schema is mapped to a Django model
  • The user will access their id_project dashboard when visiting https://website.com/dashapp/<id_project>

Implementation

I am considering two strategies:

  1. Query the database from the view through the model and cache it
  2. Get the data.csv from an s3 path s3://domain.com/projects/<id_project>

With option 1, I am stuck on the concept of passing the data. All I have found online concerns the state, but I don't want to use the state because the full dataset of the id_project (~20MB) should be available during the session.

With option 2, I am stuck on passing the id_project from the view to the template captured within the Dash app.

Beyond solving these doubts, any new approaches are welcomed

Thanks in advance for the help!

@GibbsConsulting
Copy link
Owner

@jsulopzs if you have a lot of data, then one strategy is to manage the data within Django (eg as part of the ORM, or leveraging a cache) and then accessing it during (extended) callbacks.

@jsulopzs
Copy link
Author

jsulopzs commented May 18, 2024

Thanks for the response @GibbsConsulting. I'll take the caching approach using Redis and call the id_project from the user's dropdown selection.

Although I see a caveat:

To pass the id_project options in the dropdown, I need only to display the ones associated with the logged-in username.

I am passing the username through initial_arguments, but I wouldn't say it's a safe approach since any user can inspect the HTML and change the username value to access anyone's project.

@hetryn
Copy link

hetryn commented Jun 4, 2024

Would the view decorator @login_required prevent unauthorized access in the case of using initial_arguments?

see: https://django-plotly-dash.readthedocs.io/en/latest/access_control.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants