Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Two slides to control two charts

I’m trying to plot two figures in a chart without success. The problem is that I’m trying to add two slide controls : the first one will control the Fig1 and the second one the Fig2.

import plotly as py
import numpy as np
from plotly.graph_objs import *
import math


Years = 100



data = [dict(
        visible = False,
        name = 'Short Term Bond',
        x = np.arange(0,Years,1),
        y = Inversion * math.exp(1.05/100) ** np.arange(1,Years,1)) for Inversion in np.arange(1000, 5000, 250)]
data2 = [dict(
        visible = False,
        name = 'Long Term Bond',
        x = np.arange(0,Years,1),
        y = Inversion * math.exp(1.03/100) ** np.arange(1,Years,1)) for Inversion in np.arange(3000, 5000, 250)]
data[10]['visible'] = True
DataGraph = Data([data,data2])
Inversion = []

for i in range(len(data)):
    step = dict(
        method = 'restyle',
        args = ['visible', [False] * len(data)],
    )
    step['args'][1][i] = True
    Inversion.append(step)

sliders = [dict(
    active = 10,
    currentvalue = {"prefix": "Inversion Amount : "},
    pad = {"t": 50},
    steps = Inversion
)]

layout = dict(sliders=sliders)

fig = dict(data=DataGraph, layout=layout)

py.offline.plot(fig)

Here I only have one slide control. The error I get is :

    Valid items for 'data' at path [] under parents []:
    ['Area', 'Bar', 'Box', 'Candlestick', 'Choropleth', 'Contour',
    'Heatmap', 'Heatmapgl', 'Histogram', 'Histogram2d',
    'Histogram2dcontour', 'Mesh3d', 'Ohlc', 'Pie', 'Pointcloud', 'Scatter',
    'Scatter3d', 'Scattergeo', 'Scattergl', 'Scattermapbox',
    'Scatterternary', 'Surface']

Entry should subclass dict.

Does anyone know how to solve it ?

Your data object is a list of one-dict lists. It should instead be list of dicts.

That is, your data variable should be a dict and similarly for data2.

The problem is that I need that for the slice control