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

plotly_direct #496

Open
BatoolGasser opened this issue Apr 9, 2024 · 4 comments
Open

plotly_direct #496

BatoolGasser opened this issue Apr 9, 2024 · 4 comments

Comments

@BatoolGasser
Copy link

how can i get data from django template into dash app that integrated into it

this is the html template:

    <div class="app-container">
        {%plotly_direct name="student_performance" %}
    </div>

this is views.py:
def student_performance_display(request):
cards_data = requests.get("http://127.0.0.1:8000/cards/ab33da02-c725-4f47-85dc-7908374b267c").json()
context = {
'passed_hours': cards_data[0]['passed_hours'],
'cummulative_gpa': cards_data[0]['cummulative_gpa']
}
return render(request, 'home/student/student_performance.html', context)

i want to pass data into context into dash app 
@GibbsConsulting
Copy link
Owner

That tag doesnt support the use of initial arguments, as per the documentation

Is there a particular reason you can't use another tag, such as plotly_app or plotly_app_bootstrap?

Alternatively, you could create (or update, as appropriate) an instsance of a DashApp in your view and directly render it; this object contains the current state and so can be set to hold whatever values you wish to set.

@BatoolGasser
Copy link
Author

BatoolGasser commented Apr 19, 2024

but in my project I have 5 dash Apps integrated in 5 html templates, each app displays the data of the user that login with email and password, So there exist a lot of details , a lot of Apis used in each part of the app
so i think creating or updating each part in each app will be dispersed

and the reason that i do not prefer plotly_app and 'plotly_app_bootstrap' that the dash app will be injected as iframe and it makes scroller and effects css styles

the sidebar is html , css and the remaining is dash apps
int1
int2

@BatoolGasser
Copy link
Author

That tag doesnt support the use of initial arguments, as per the documentation

Is there a particular reason you can't use another tag, such as plotly_app or plotly_app_bootstrap?

Alternatively, you could create (or update, as appropriate) an instsance of a DashApp in your view and directly render it; this object contains the current state and so can be set to hold whatever values you wish to set.

Or what do you mean by updating an instance of the dash app direclty in views?
i understand that i will get the data from the api like this but i have many apis for each part of the dash app, so i will have many variables
and creating all dash apps in views to access it , So how it will be rendered in html template (with sidebar)
and the data will change by different users so i need it to be fash

def student_performance_display(request):
    cards_data = requests.get("http://127.0.0.1:8000/cards/ab33da02-c725-4f47-85dc-7908374b267c").json()
    context = {
        'passed_hours': cards_data[0]['passed_hours'],
        'cummulative_gpa': cards_data[0]['cummulative_gpa']
    }
    return render(request, 'student_performance', context)

@GibbsConsulting
Copy link
Owner

@BatoolGasser getting that data is probably best separated out (if the URL is constant then it never changes; if it does change then presumably it depends on the current user/session/request; either way it is likely one or other of the cache and ORM are the best places for it).

Once you've got it somewhere, you can then use the information. If its available through the current user session or similar, then an extended callback provides access to the Django request.

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

2 participants