I have this module with function that I am calling with jquery.Ajax()
import pandas_datareader.data as web
from datetime import datetime
import plotly.offline as offline
import plotly.graph_objs as go
import pandas as pd
def plot_watchlist(query_data):
start = datetime(2015, 1, 1)
end = datetime(2015, 11, 1)
plots = []
for row in query_data:
ticker = row['code_ticker']
source = row['source']
#name = row['name']
f = web.DataReader([ticker], source, start, end)
#Prepare x and y data to be ploted
y_data = f['Close'][ticker]
x_data = pd.to_datetime(f['Close'].index.values)
stock_chart = offline.plot({
"data": [go.Scatter(x=x_data,y=y_data)]
}, output_type="div", showlink = False)
plots.append(stock_chart)
return (plots)
This function is called within:
@app.route('/getWatchlist'):
def getWatchlist():
....
(some query to get the data)
...
plots = plot_watchlist(query_data)
This is supposed to create a list of plots that get returned and rendered.
I've added print statements inside getWatchlist( ) function (which prints something) and inside plot_watchlist(query_data) which does not print anything.
Any suggestions or ideas about it? Also, any recommendations/alternative to plotly? Is it better to explore plotly.js instead of plotly in python? Other plotting packages like HighCharts?
This is my js script that triggers the function.
$(function() {
$.ajax({
url: '/getWatchlist',
type: 'GET',
success: function(res) {
var div = $('<div>')
.attr('class', 'charts');
var chartObj = JSON.parse(res);
var chart = '';
$.each(chartObj, function(index, value) {
chart = $(div).clone();
$(chart).html(value);
$('.charts').append(chart);
});
},
error: function(error) {
console.log(error);
}
});
});
I have a local copy of the code and runs fine in my machine (renders plots as expected) Thank you!