Snippets

Michael Lee plotly embed for flask

Created by Michael Lee last modified
<!DOCTYPE html>
<html>
    <head>
        <title>Simple Paper Trader</title>
        <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
        <script src="https://cdn.rawgit.com/etpinard/plotlyjs-finance/master/plotlyjs-finance.js"></script>
    </head>
    <body>
        <div id="plotly" style="width:600px;height:400px;"></div>

        <script>
            var fig = PlotlyFinance.createCandlestick(
                {
                    open:  [{{ quotes|map(attribute='Open')|join(',')}}  ],
                    high:  [{{ quotes|map(attribute='High')|join(',')}}  ],
                    low:   [{{ quotes|map(attribute='Low')|join(',')}}   ],
                    close: [{{ quotes|map(attribute='Close')|join(',')}} ]
                }
            );
            Plotly.newPlot('plotly', fig.data, fig.layout);
        </script>
    </body>
</html>
1
2
3
4
@app.route('/plotly_test')
def plotly_test():
    qs = fetch_quotes('AAPL', datetime.date(2007, 6, 1), datetime.date(2007, 7, 31))
    return render_template('plotly.html', quotes=qs)

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.