import ipywidgets as widgets
import plotly.graph_objs as go
import plotly.express as px

"""
Explanation: these notes will not display in the slideshow
interactive dashboard application rendered as a slideshow
using

ipywidgets

plotly (express)


voila

reveal
End of explanation
"""


iris = px.data.iris()

iris.head()

fig = go.FigureWidget()
keys = list(iris.keys()[:4])

@widgets.interact(x=keys, y=keys[::-1])
def update_px(x, y):
    p = px.scatter(iris, x, y, color='species', width=800, height=600)
    for i in range(len(p.data)):
        fig.data = []
    fig.update(data = [d.to_plotly_json() for d in p.data])
    fig.plotly_relayout(p.layout.to_plotly_json())
    
fig

"""
Explanation: loading the iris dataset
End of explanation
"""


fig2 = go.FigureWidget()
cmaps = {'Plotly': px.colors.qualitative.Plotly, 'D3': px.colors.qualitative.D3,
         'Pastel': px.colors.qualitative.Pastel, 'Vivid': px.colors.qualitative.Vivid}

@widgets.interact(color_discrete_sequence=cmaps)
def update_cmap(color_discrete_sequence):
    p = px.scatter_matrix(iris, dimensions=keys, color='species', color_discrete_sequence=color_discrete_sequence,
                          width=800, height=600)
    for i in range(len(p.data)):
        fig2.data = []
    fig2.update(data = [d.to_plotly_json() for d in p.data])
    fig2.plotly_relayout(p.layout.to_plotly_json())
    
fig2

"""
Explanation: inspiration

https://plot.ly/python/plotly-express/
https://community.plot.ly/t/plotly-express-hover-selecting-event-only-partially-working/22136

alternatively, view pairwise relationships at a glance, with a qualitative colormap of your choice
End of explanation
"""


