Как автообновлять данные и вежливо строить графики Plotly в Django
Здравствуйте, как сделать автообновление и автообновление, чтобы я мог получать данные в реальном времени на графике plotly в Django (без нажатия на кнопку обновления в браузере)
Вот мой код:
в (views.py)
from plotly.offline import plot
import plotly.graph_objs as go
import yfinance as yf
def result(request):
stock_ticker = request.GET['num1']
period = request.GET['num2']
interval = request.GET['num3']
data = yf.download(tickers=stock_ticker, period = period, interval = interval, auto_adjust = True, threads = True, proxy = None)
data['Date'] = data.index
def candlestick():
figure = go.FigureWidget(data = [go.Candlestick(x=data['Date'],high=data['High'],low=data['Low'],open=data['Open'],close=data['Close'],)])
figure.update_layout(width=1400, height=800, title=f'{stock_ticker} Historical price', plot_bgcolor="white")
figure.update_yaxes(showline=True, linecolor='lightgray', showgrid=True, gridwidth=0.5, gridcolor='lightgray', mirror=True)
figure.update_xaxes(showline=True, linecolor='lightgray', mirror=True, rangebreaks=[dict(bounds=["sat", "mon"]), dict(bounds=[16, 9.5], pattern="hour"),])
figure.update_traces(visible=True, selector=dict(type='candlestick'))
candlestick_div = plot(figure, output_type='div', config = {"displaylogo": False})
return candlestick_div
return render(request, 'index.html', {'candlestick':candlestick()})
также в (index.html)
{% block content %}
<center>
{{ candlestick | safe}}
</center>
{% endblock %}