@delsim, thank you for your fast reply!
Please find below the sections of my code that I use for creating a specified outcome.
Could you please comment if you see there anything that is strange/ wrong?
Thank you for your support!
++++++++++++++++++++++++++++++++++++
View:
class HomePageView(ListView, JSONResponseMixin):
model = MyModel
filter_class = MyFilter
formhelper_class = MyListFormHelper
template_name = “view_data/home_view.html”
context_object_name = ‘dash_inputs’
context_filter_name = ‘filter’
def get_queryset(self, **kwargs):
qs = super(ListView, self).get_queryset()
self.filter = self.filter_class(self.request.GET, queryset=qs)
self.filter.form.helper = self.formhelper_class()
pivot_table = pivot(self.filter.qs, ['parameter1', 'parameter2'], 'timeref', 'value') ###the resulting object is Django Queryset###
df = read_frame(pivot_table)
df = df.round(0)
df = df.to_dict('records')
mydict = {}
mydict['id'] = 'table'
mydict['data'] = df
return mydict
def get_context_data(self, **kwargs):
context = super(ListView, self).get_context_data()
context[self.context_filter_name] = self.filter
return context
++++++++++++++++++++++++++++++++++++
Default data:
qs = MyModel.objects.values(‘parameter1’, ‘parameter2’, ‘timeref’, ‘value’).exclude(parameter1=None).exclude(parameter2=None)
pivot_table = pivot(self.filter.qs, [‘parameter1’, ‘parameter2’], ‘timeref’, ‘value’)
df = read_frame(pivot_table)
df = df.round(0)
Dash app:
app = DjangoDash(‘SimpleExample’, external_stylesheets=external_stylesheets) # replaces dash.Dash
app.layout = html.Div([
dash_table.DataTable(
id=‘table’,
columns=[{“name”: i, “id”: i} for i in df.columns],
data=df.to_dict(‘records’),
style_data_conditional=[
{
‘if’: {‘row_index’: ‘odd’},
‘backgroundColor’: ‘rgb(235, 235, 235)’
},
],
style_cell_conditional=[
{
‘if’: {‘column_id’: ‘parameter1’},
‘minWidth’: ‘180px’, ‘width’: ‘180px’, ‘maxWidth’: ‘180px’,
‘textAlign’: ‘center’
},
{
‘if’: {‘column_id’: ‘parameter2’},
‘minWidth’: ‘180px’, ‘width’: ‘180px’, ‘maxWidth’: ‘180px’,
‘textAlign’: ‘center’
}
],
css=[{
‘selector’: ‘.dash-cell div.dash-cell-value’,
‘rule’: ‘display: inline; white-space: inherit; overflow: inherit; text-overflow: inherit;’
}],
style_cell={
‘whiteSpace’: ‘no-wrap’,
‘overflow’: ‘hidden’,
‘textOverflow’: ‘ellipsis’,
},
style_header={
‘backgroundColor’: ‘rgb(230, 230, 230)’,
‘fontWeight’: ‘bold’
},
),
])
++++++++++++++++++++++++++++++++++++
Template:
{%load plotly_dash%}
…
{%plotly_app name=“SimpleExample” initial_arguments=“dash_inputs” ratio=1%}
…