Dashboard: fix plots
This commit is contained in:
parent
5434c7d6ef
commit
c8ca68e1a4
3 changed files with 28 additions and 20 deletions
|
@ -3,9 +3,11 @@ from pickle import loads
|
|||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from typing import Any
|
||||
# from typing import Any
|
||||
|
||||
from matplotlib.figure import Figure
|
||||
from plotly.graph_objs._figure import Figure as PlotlyFigure
|
||||
from sqlmodel import Field, Relationship, String, JSON
|
||||
from pydantic import BaseModel
|
||||
import pandas as pd
|
||||
|
@ -110,18 +112,22 @@ class DashboardPageCommon:
|
|||
#f'in {self.get_attachment_file_name()}')
|
||||
return self.attachment
|
||||
|
||||
def get_page_df(self):
|
||||
def get_page_df(self) -> pd.DataFrame | None:
|
||||
"""
|
||||
Get the dataframe of the page
|
||||
"""
|
||||
if not self.df:
|
||||
return
|
||||
return None
|
||||
try:
|
||||
return pd.read_pickle(BytesIO(self.df), compression=None)
|
||||
df = pd.read_pickle(BytesIO(self.df), compression=None)
|
||||
except KeyError:
|
||||
raise NotADataframeError()
|
||||
if isinstance(df, dict):
|
||||
return None
|
||||
else:
|
||||
return df
|
||||
|
||||
def get_plot(self):
|
||||
def get_plot(self) -> PlotlyFigure | None:
|
||||
if self.plot is not None:
|
||||
return loads(self.plot)
|
||||
|
||||
|
@ -293,7 +299,8 @@ class Dashboard(BaseModel):
|
|||
html: str | None = None
|
||||
attachment: str | None = None
|
||||
dfData: list = []
|
||||
plotData: str | None = None
|
||||
plotData: list[dict] | None = None
|
||||
plotLayout: dict[str, Any] | None = None
|
||||
notebook: str | None = None
|
||||
expandedPanes: list[str] | None = None
|
||||
sections: list[DashboardSection] | None = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue