I’m trying to create an interactive dashboard similar to what is shown in the 2nd example here, but I want to output it to html in offline mode rather than using the plotly servers or a notebook, I’m having trouble messing about with the code. From the 2nd example, to get a drop down widget that will filter a chart it says:
import pandas as pd
import plotly.plotly as py
from ipywidgets import widgets
from IPython.display import display
from plotly.graph_objs import *
from plotly.widgets import GraphWidget
# we will define a function that will handle the input from the dropdown widget
def update_plot(complaint):
is_noise = complaints['Complaint Type'] == complaint['new']
temp = complaints[is_noise]
data = temp.groupby(complaints['Borough'])['Complaint Type'].count()
x = []
y = []
for i in range(len(data)):
x.append(data.index[i])
y.append(data[i])
graph.restyle({
'x': [x],
'y': [y],
})
graph.relayout({'title': 'Number of {} Complaints in New York by Borough'.format(complaint['new'])})
# we will define both the dropdown widget, as well as the graph widget
w = widgets.Dropdown(
options= list(complaints['Complaint Type'].unique()),
value='Noise - Street/Sidewalk',
description='Complaint Type:',
)
graph = GraphWidget('https://plot.ly/~kevintest/1176/')
# observe will set a listener for activity on our dropdown menu
w.observe(update_plot, names="selected_label")
display(w)
display(graph)
Because I’m using offline plotting rather than a notebook, I usually plot the data at the end of my code with (for example):
data = [trace0, trace1,trace2,trace3,trace4,trace5]
fig = go.Figure(data = data, layout = layout)
py.offline.plot(fig, show_link=False, filename="Bubble.html")
Is it possible to alter it slightly so I can export the drop down widget with my graph in offline mode? I know inbuilt drop downs have recently been implemented, but I’m not sure if they have the level of filtering I require for my graphs (as in I want to get the drop down embedded within my output.)