Consider this code:
sums = df.groupby('Date', as_index=False)[['Payment', 'Income']].sum()
med = df.groupby('Date', as_index=False)['Margin'].median()
sums.insert(3, 'Margin', med['Margin'])
scafig = ms(specs=[[{"secondary_y": True}]])
scafig.add_trace(go.Scatter(x=sums['Date'], y=sums[subj], fill='tozeroy', name=subj, fillcolor='yellow'), secondary_y=False)
scafig.add_trace(go.Scatter(x=sums['Date'], y=sums['Margin'], line={'color': 'grey', 'width': 1, 'dash': 'dot'}, name='Platform share', visible='legendonly'), secondary_y=True)
scafig.update_yaxes(title_text='Daily revenue', secondary_y=False, range=[0, 200000])
scafig.update_yaxes(title=None, secondary_y=True, range=[0, 0.30])
scafig.update_layout(xaxis={'rangeslider': {'visible': True, 'range': ['2021-01-01', '2020-02-15']}, 'rangebreaks': [{'pattern': 'day of week', 'bounds': ['sat', 'mon']}]})
This effectively creates a dataframe with 2 separate calculations and then a figure with 2 traces (one of them hidden by default). Then it enables the rangeslider
that is supposed to show a limited range by default.
The problem is that the documentation is not particularly clear on how the range
attribute works. I tried various ways, but nothing seems to work - the range goes to the default value (which is βeverythingβ) no matter what. Either Iβm doing something wrong, or I misunderstand the purpose of the range
attribute, or there is something Iβm not aware of.
Is there a way to make the rangeslider
default to a particular time period instead of showing the whole timeline?
Alternatively, it there a way to use rangeselector
for the same purpose? I.e. make a particular button
created by that component the go-to one?