我想删除一个数据框(在OHLCV的图形中使用),如果更改了特定的下拉列表,则用新数据重新创建它。简而言之,如果我更改提取交换数据的时间间隔(1m,5m,15m,30m,1h等),则希望从数据帧“重置” /“擦除”数据。
我需要在底部添加选项来计算市场变化。因此,我假设类似的方法可能有效,但是我无法弄清楚如何将新的空白数据帧传递回 update_graph_scatter
AppendedValue = pd.DataFrame()
def clear_df():
del AppendedValue
AppendedValue = pd.DataFrame()
return AppendedValue
@app.callback(Output('dropdown_interval', 'value'), [Input('dropdown_interval', 'options')])
def update_interval_value(intervals):
AppendedValue = clear_df()
return intervals[0]['value']
#POPULATES THE GRAPH USING A 20 SECOND INTERVAL. EVERY 20 SECONDS THE CALLBACK TRIGGERS "UPDATE_GRAPH_SCATTER"
@app.callback(Output('crypto-live-graph', 'figure'), [Input('dropdown_exchange', 'value'), Input('dropdown_ticker', 'value'), Input('dropdown_interval', 'value'), Input('arglist', 'value'), Input('graph-update', 'n_intervals')], [State('crypto-live-graph', 'figure')])
def update_graph_scatter(dropdown_exchange, dropdown_ticker, dropdown_interval, arglist, graphupdate, figure):
global AppendedValue
########################## PULL OHLCV DATA ###################################
PullValues = bf.trader()
funcName = dropdown_exchange.lower() + '_data'
exchange = dropdown_exchange.lower()
#AppendedValue = getattr(PullValues, funcName)(dropdown_ticker, dropdown_interval)
#NewDateTimes = AppendedValue.index
########################## END PULL OHLCV DATA ###############################
if AppendedValue.empty:
AppendedValue,last_date = getattr(PullValues, funcName)(dropdown_ticker, dropdown_interval)
else:
AppendedValue, last_date = append_new_bars(AppendedValue, exchange, dropdown_ticker, PullValues, dropdown_interval)
NewDateTimes = AppendedValue.index
########################## CREATE OHLCV FORMAT ###############################
trace = Candlestick(
x=NewDateTimes,
open=AppendedValue['open'],
high=AppendedValue['high'],
low=AppendedValue['low'],
close=AppendedValue['close'],
showlegend=False,
name='BTC/USD',
legendgroup='BTC/USD',
increasing=dict(line=dict(color=colorscale[2])),
decreasing=dict(line=dict(color=colorscale[4])),
yaxis='y1'
)
data=[trace]