GibbsConsulting / django-plotly-dash

Expose plotly dash apps as django tags
MIT License
548 stars 124 forks source link

plotly_direct #496

Open BatoolGasser opened 5 months ago

BatoolGasser commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 4 months ago

@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.