i tried to create the dashboard to my django application, with django_plotly_dash


import pandas as pd
import dash
from dash import html, dcc
from django_plotly_dash import DjangoDash
from .models import Client, Data, RDV
import plotly.express as px

# Récupérer les données depuis les modèles Django
data = Data.objects.values('coll', 'client', 'tot_net')
clients = Client.objects.values('nom', 'prestations_soins', 'prestations_onglerie', 'prestations_coiffure')
rdv = RDV.objects.values('client', 'coll_reel')

# Convertir les données en DataFrames (à l'aide de pandas)
df_data = pd.DataFrame(list(data))
df_clients = pd.DataFrame(list(clients))
df_rdv = pd.DataFrame(list(rdv))

# Analyse des ventes par collaborateur (coll)
ventes_par_coll = df_data.groupby('coll')['tot_net'].sum().reset_index()

# Analyse des ventes par client
ventes_par_client = df_data.groupby('client')['tot_net'].sum().reset_index()

# Calcul du nombre total de prestations par client
df_clients['nombre_total_prestations'] = df_clients['prestations_soins'] + df_clients['prestations_onglerie'] + df_clients['prestations_coiffure']

# Nombre de rendez-vous par client
rdv_par_client = df_rdv['client'].value_counts().reset_index()
rdv_par_client.columns = ['client', 'nombre_de_rdv']

# Nombre de rendez-vous par collaborateur (coll)
rdv_par_coll = df_rdv['coll_reel'].value_counts().reset_index()
rdv_par_coll.columns = ['coll_reel', 'nombre_de_rdv']

# Créer une application Dash
app = DjangoDash('dashboard_app')

# Création des graphiques avec Plotly Express
fig_ventes_coll = px.bar(ventes_par_coll, x='coll', y='tot_net', title='Ventes par Collaborateur')
fig_ventes_client = px.bar(ventes_par_client, x='client', y='tot_net', title='Ventes par Client')
fig_prestations_clients = px.bar(df_clients, x='nom', y='nombre_total_prestations', title='Nombre de Prestations par Client')
fig_rdv_clients = px.bar(rdv_par_client, x='client', y='nombre_de_rdv', title='Nombre de Rendez-vous par Client')
fig_rdv_coll = px.bar(rdv_par_coll, x='coll_reel', y='nombre_de_rdv', title='Nombre de Rendez-vous par Collaborateur')

# Mise en page du tableau de bord
app.layout = html.Div(children=[
    html.H1(children='Analyse des Données'),

    # Graphique des ventes par collaborateur

    # Graphique des ventes par client

    # Graphique du nombre de prestations par client

    # Graphique du nombre de rendez-vous par client

    # Graphique du nombre de rendez-vous par collaborateur
import dash

from django.shortcuts import render

from openpyxl import load_workbook

from .models import Client, Data, RDV

from .models import Catalogue

from django.http import HttpResponse

#from django.shortcuts import render

from .dashboard import app

# MonApp/views.py

from dash import Dash, html, dcc

import plotly.express as px

#from django_plotly_dash import DjangoDash

#from django.shortcuts import render

from django_plotly_dash import DjangoDash

import pandas as pd
def dashboard_view(request):
    # Rendre la vue avec le tableau de bord Dash
    dash_content = app.to_html()
    context = {'dash_content': dash_content}
    return render(request, 'ManagerSalon360/dashboard.html', {'dash_content': context})

my dashboard.html

{% extends 'ManagerSalon360/base.html' %}
{% block content %}
    <meta charset="UTF-8">
    <div id="graph">
        {{ dash_content | safe }}
{% endblock %}

the error that i received to my terminal

Internal Server Error: /ManagerSalon360/dashboard/
Traceback (most recent call last):
  File "D:\MonLogiciel\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "D:\MonLogiciel\venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\MonLogiciel\ManagerSalon360\views.py", line 239, in dashboard_view
    dash_content = app.to_html()
AttributeError: 'DjangoDash' object has no attribute 'to_html'
[08/Jan/2024 17:34:27] "GET /ManagerSalon360/dashboard/ HTTP/1.1" 500 67831

Please help me. I dont know what i dont doing well

Side note: When posting code, templates, or tracebacks, enclose each block of code between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code, then another line of ```. This forces the forum software to keep your code properly formatting. (I’ve taken the liberty of editing your original post for this, please remember to do this in the future. Also, I suggest you go through the “discobot” tutorial and exercises to become familiar with the features of the forum.)

Looking at the error message in the traceback:

What documentation are you looking at that gives you an indication that a DjangoDash object has a to_html function?

Good evening sir, I understand, thank you so much. I will make sure I don’t make the same mistake again. Thank you also for formatting my code to make it easier to understand

I saw it in a django_plotly_dash documentation that DjangoDash can have the function dash_content = app.index() or dash_content = app.to_html() But the both functions gave me almost the same errors.

Please provide the link to the documentation that you are referring to. (There’s a chance it might be out-dated or referring to something else.)

Also please specify what versions of Python, Django, and django-plotly-dash you are using.

Okay, I will look for the link and send it to you.
I use Python 3.9, Django 3.2.23, django_plotly_dash 2.1.0.

There is py pip list
(venv) PS D:\MonLogiciel> pip list
Package Version

ansi2html 1.9.1
asgiref 3.7.2
async-timeout 4.0.3
attrs 23.2.0
autobahn 23.6.2
Automat 22.10.0
beautifulsoup4 4.12.2
blinker 1.7.0
Brotli 1.1.0
certifi 2023.11.17
cffi 1.16.0
channels 2.4.0
channels-redis 4.1.0
charset-normalizer 3.3.2
click 8.1.7
colorama 0.4.6
constantly 23.10.4
cryptography 41.0.7
daphne 2.5.0
dash 2.9.3
dash-bootstrap-components 0.13.1
dash-core-components 2.0.0
dash_daq 0.5.0
dash-html-components 2.0.0
dash-renderer 1.3.0
dash-table 5.0.0
distlib 0.3.8
Django 3.2.23
django-asset-definitions 1.0.0
django-autoslug 1.9.9
django-bootstrap4 23.4
django-cors-headers 4.3.1
django-dash 0.6.1
django-dashboards 0.1.7
django-extensions 3.2.3
django-nine 0.2.7
django-plotly-dash 2.1.0
django-redis 5.4.0
django-tinymce 3.6.1
dpd-components 0.1.0
dpd-static-support 0.0.5
easy-thumbnails 2.8.5
et-xmlfile 1.1.0
feedparser 6.0.11
filelock 3.13.1
Flask 2.1.3
Flask-Compress 1.14
future 0.18.3
hyperlink 21.0.0
idna 3.6
importlib-metadata 7.0.1
incremental 22.10.0
itsdangerous 2.1.2
Jinja2 3.1.2
MarkupSafe 2.1.3
msgpack 1.0.7
nest-asyncio 1.5.8
numpy 1.26.3
openpyxl 3.1.2
optional-django 0.3.0
packaging 23.2
pandas 2.1.4
patsy 0.5.6
pif 0.8.2
Pillow 10.1.0
pip 23.3.2
platformdirs 4.1.0
plotly 5.18.0
plotly-express 0.4.1
polyfill 0.0.1
pyasn1 0.5.1
pyasn1-modules 0.3.0
pycparser 2.21
pyOpenSSL 23.3.0
python-dateutil 2.8.2
pytz 2023.3.post1
react 4.3.0
redis 5.0.1
requests 2.31.0
retrying 1.3.4
scipy 1.11.4
service-identity 23.1.0
setuptools 69.0.3
sgmllib3k 1.0.0
six 1.16.0
soupsieve 2.5
sqlparse 0.4.4
statsmodels 0.14.1
tenacity 8.2.3
transliterate 1.10.2
Twisted 23.10.0
twisted-iocpsupport 1.0.4
txaio 23.1.1
typing_extensions 4.9.0
tzdata 2023.4
Unidecode 1.3.7
urllib3 2.1.0
virtualenv 20.25.0
vishap 0.1.5
Werkzeug 2.0.3
whitenoise 6.6.0
zipp 3.17.0
zope.interface 6.1

I’m a beginner in python, I may have referred to an outdated or bad document. So I would appreciate it if you could help me please.

I will briefly present my context to you. I have a basic application that I created on django. My django model contains classes that are used for other purposes. I want to insert a dashboard into this application whose data to use for the graphs comes from my django models. The research carried out for this purpose has allowed me to advance so far or I am stuck. This is why I approached the forum to try to find a solution.

I can understand that, and we’re here to help.

My (admittedly brief) research on django-plotly-dash doesn’t show any function to_html as being available on the DjangoDash object. Since I’m not familiar with the library, my assumption is that I’m overlooking something. That’s why I was asking you for your reference.

If you don’t have one, then we can work from the position that it doesn’t exist. In that case, I suggest you go to the official docs, to see how you are supposed to use it in your application.

And, as I always suggest in situations where someone is working with a new library that they are unfamiliar with, start small. Work to get the most basic example working, then start adding the features needed for your application to do what it needs to do. Don’t try to solve your entire set of requirements all at once.