import vizro.models as vm
import plotly.graph_objects as go
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
from vizro.models.types import capture
from vizro.figures import kpi_card
import dash
from dash import dcc, html, Input, Output, callback, clientside_callback
import pandas as pd
import copy
df = pd.read_csv('data/dashboard.csv')
@capture("graph")
def custom_scatter_click(data_frame, width=500, height=400):
data_frame = data_frame
fig = px.scatter(
data_frame,
x='tsne1',
y='tsne2',
color='metal_cat',
hover_data={'metal': True, 'elastomer': True, 'tsne1': False, 'tsne2': False, 'metal_cat':False}
)
fig.update_layout(width=width, height=height, xaxis_title="Reduced dimension 1",
yaxis_title="Reduced dimension 2",
xaxis=dict(tickfont=dict(size=16, color='black')),
yaxis=dict(tickfont=dict(size=16, color='black'))
)
fig.update_layout(
xaxis=dict(showticklabels=False),
yaxis=dict(showticklabels=False)
)
fig.update_layout(showlegend=False, xaxis_showgrid=False, yaxis_showgrid=False)
return fig
@capture("graph")
def custom_hist(data_frame, x):
fig = px.histogram(data_frame, x=x)
fig.update_layout(#width=500, height=400,
xaxis_title=None,
xaxis=dict(tickfont=dict(size=16, color='black')),
yaxis=dict(tickfont=dict(size=16, color='black'))
)
fig.update_xaxes(categoryorder='total descending')
fig.update_xaxes(tickangle=80)
return fig
first_page = vm.Page(
title="Data",
components=[
vm.AgGrid(
figure=dash_ag_grid(df),
),
],
)
second_page = vm.Page(
title="Materials Analysis",
layout=vm.Grid(grid=[[0, 0, -1], [1, 1, -1], [1, 1, -1]],
row_gap="10px", col_gap="20px",
row_min_height='450px', col_min_width='230px'),
components = [
vm.Graph(
figure=custom_hist(df, x='metal_cat'),
title="Metals"
),
vm.Graph(figure=custom_scatter_click(df, width=650, height=650),
title="Metal-Elastomer Universe"
)
]
)
dashboard = vm.Dashboard(
pages=[first_page, second_page],
title = "Metal-Elastomer",
navigation=vm.Navigation(nav_selector=vm.NavBar(
items = [
vm.NavLink(label='Data', pages=["Data"], icon="database"),
vm.NavLink(label='Charts', pages=["Materials Analysis"], icon="bar_chart"),
]
)
)
)
Vizro().build(dashboard).run()