Dropdown with user input for subplots

Hello everyone!

I am trying to make a chart that would be updatable by user input. So the user can set any time and date for the beginning and end of time series, and it would update it. However, every time I would get a different chart, so it needs to be recalculated for any period. I’ve tried to do it using examples from the web-site, but nothing happens in the end. What am I doing wrong here?

Thank you!

fig = go.FigureWidget(make_subplots(
rows=2, cols=1,
shared_xaxes=True,
specs=[[{“type”: “Candlestick”}],
[{“type”: “table”}]]
))

    textbox1 = widgets.Dropdown(
        description='Start date:   ',
        value=table[0][1],
    )
    textbox2 = widgets.Dropdown(
        description='End date:   ',
        value=table[1][1],
    )

    if len(self.strategy_params['signal_params']['curr_generators'].items()) == 1:
        fig.add_trace(go.Candlestick(x=self._data.index,
                                             open=self._data['Open'],
                                             high=self._data['High'],
                                             low=self._data['Low'],
                                           close=self._data['Close']), row=1, col=1)
    else:
        single_cur = False
        fig.add_trace(go.Scatter(x=self._data.index, y=self.calc_of_index()['strategy'], mode='lines', name='lines'),
                      row=1, col=1)

    fig.add_trace(go.Scatter(x=self._data.index, y=self.balance_list['strategy'], mode='lines', name='lines'), row=1, col=1)


    fig.add_trace(
        go.Table(
            header=dict(
                values=[table[i][0] for i in range(len(table))],
                font=dict(size=10),
                align="left"
            ),
            cells=dict(
                values=[table[i][1] for i in range(len(table))],
                align="left")
        ),
        row=2, col=1
    )


    fig.update_layout(xaxis_rangeslider_visible=False, template='plotly_dark')

    def response(change):
            start = textbox1.value
            end = textbox2.value
            for currency in data.keys():
                data[currency] = get_data('./data', currency, 'USD', '1h', 'Bitstamp',
                                          start_date=start,last_date=end, update_data=False)
                self.strategy_update()
                signals = pd.Series(self._res.backtest_list[0].strategy.stack.algos[2].signals)
                self._data_calculator(signals)

            if single_cur:
                fig.update_traces(x=self._data.index,
                                             open=self._data['Open'],
                                             high=self._data['High'],
                                             low=self._data['Low'],
                                           close=self._data['Close'], col=1)

    textbox1.observe(response, names="value")
    textbox2.observe(response, names="value")

    container = widgets.HBox([textbox1, textbox2])
    b = widgets.VBox([container, fig])

I have tried to run an example code from plotly tutorials and it does not show anything as well.

import plotly.graph_objs as go
import plotly.offline as py
import chart_studio.plotly as pyp
import plotly

from ipywidgets import interactive, HBox, VBox, widgets, interact

py.init_notebook_mode()

load fig

fig = pyp.get_figure(“https://plot.ly/~jordanpeterson/889”)

find the range of the slider.

xmin, xmax = fig[‘layout’][‘xaxis’][‘range’]

create FigureWidget from fig

f = go.FigureWidget(data=fig.data, layout=fig.layout)

slider = widgets.FloatRangeSlider(
min=xmin,
max=xmax,
step=(xmax - xmin) / 1000.0,
readout=False,
description=‘Time’)
slider.layout.width = ‘800px’

our function that will modify the xaxis range

def update_range(y):
f.layout.xaxis.range = [y[0], y[1]]

display the FigureWidget and slider with center justification

vb = VBox((f, interactive(update_range, y=slider)))
vb.layout.align_items = ‘center’
vb

I cannot try your code so it is quite hard to know what is wrong but I would suggest you to use the widgets.interactive method for your callbacks. On some platforms, like JupyterLab, output generated by widget callbacks (for instance, functions attached to the .observe method on widget traits, or to the .on_click method on button widgets) are not displayed anywhere and the the debugging errors in callbacks are muted. (see Output widgets: leveraging Jupyter’s display system — Jupyter Widgets 8.0.0b0 documentation)

Additionally:

The update_traces method is meant to update all traces with compatible properties. (see Creating And Updating Figures) not to update a specific trace. Since one of them is Table it probably won’t work.
You can access and update a specific trace also with:
fig.data[index of your trace].update(x=.., y=.. etc.)

Just if you post some code, make sure to make a minimal example of your problem that is also testable by others.
hope it helps, Alex-