Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stock Example Stuck Loading #93

Open
JKatsenelinboigen opened this issue Feb 17, 2021 · 0 comments
Open

Stock Example Stuck Loading #93

JKatsenelinboigen opened this issue Feb 17, 2021 · 0 comments

Comments

@JKatsenelinboigen
Copy link

JKatsenelinboigen commented Feb 17, 2021

I am using python 3.8.3 on Windows 10. All dependencies are fully up to date.

I copied Example 2's code making only necessary changes, but the chart is stuck loading when i run my web app.
image
image

The same is the case when i run the second example on the dataspyre documentation found here:
https://dataspyre.readthedocs.io/en/latest/getting_started.html#example-2-tabs-and-tables

The first example runs fine

Here is my code, the only changes i made are from urllib.request import urlopen and result = urllib.urlopen(api_url).read() as i am on python 3.8.3
`
from spyre import server

import pandas as pd
from urllib.request import urlopen
import json

class StockExample(server.App):
title = "Historical Stock Prices"

inputs = [{        "type":'dropdown',
                "label": 'Company',
                "options" : [ {"label": "Google", "value":"GOOG"},
                              {"label": "Yahoo", "value":"YHOO"},
                              {"label": "Apple", "value":"AAPL"}],
                "key": 'ticker',
                "action_id": "update_data"}]

controls = [{    "type" : "hidden",
                "id" : "update_data"}]

tabs = ["Plot", "Table"]

outputs = [{ "type" : "plot",
                "id" : "plot",
                "control_id" : "update_data",
                "tab" : "Plot"},
            { "type" : "table",
                "id" : "table_id",
                "control_id" : "update_data",
                "tab" : "Table",
                "on_page_load" : True }]

def getData(self, params):
    ticker = params['ticker']
    # make call to yahoo finance api to get historical stock data
    api_url = 'https://chartapi.finance.yahoo.com/instrument/1.0/{}/chartdata;type=quote;range=3m/json'.format(ticker)
    result = urllib.urlopen(api_url).read()
    data = json.loads(result.replace('finance_charts_json_callback( ','')[:-1])  # strip away the javascript and load json
    self.company_name = data['meta']['Company-Name']
    df = pd.DataFrame.from_records(data['series'])
    df['Date'] = pd.to_datetime(df['Date'],format='%Y%m%d')
    return df

def getPlot(self, params):
    df = self.getData(params).set_index('Date').drop(['volume'],axis=1)
    plt_obj = df.plot()
    plt_obj.set_ylabel("Price")
    plt_obj.set_title(self.company_name)
    fig = plt_obj.get_figure()
    return fig

app = StockExample()
app.launch(port=9093)`

Any help with this would be appreciated, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant