def index(): # default list of countries to be available for filtering country_codes = [['Canada', 'CAN'], ['United States', 'USA'], ['Brazil', 'BRA'], ['France', 'FRA'], ['India', 'IND'], ['Italy', 'ITA'], ['Germany', 'DEU'], ['United Kingdom', 'GBR'], ['China', 'CHN'], ['Japan', 'JPN']] # Send the list of countries selected by the user to the website if (request.method == 'POST') and request.form: figures = return_figures(request.form) countries_selected = [] for country in request.form.lists(): countries_selected.append(country[1][0]) # Get all countries after the page loaded else: figures = return_figures() countries_selected = [] for country in country_codes: countries_selected.append(country[1]) # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figuresJSON, all_countries=country_codes, countries_selected=countries_selected)
def index(): country_codes = [["South Sudan", "SS"], ["Liberia", "LR"], ["Yemen", "YE"], ["Malawi", "MW"], ["Niger", "NE"], ["Mozambique", "MZ"], ["Central African Republic", "CF"]] # Parse the POST request countries list if (request.method == 'POST') and request.form: figures = return_figures(request.form) countries_selected = [] for country in request.form.lists(): countries_selected.append(country[1][0]) # GET request returns all countries for initial page load else: figures = return_figures() countries_selected = [] for country in country_codes: countries_selected.append(country[1]) # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figuresJSON, all_countries=country_codes, countries_selected=countries_selected)
def index(): # List of countries for filter country_codes = [('Brazil', 'BRA'), ('India', 'IND'), ('Mexico', 'MEX'), ('South Africa', 'ZAF'), ('China', 'CHN')] # Parse the POST request countries list if (request.method == 'POST') and request.form: figures = return_figures(request.form) countries_selected = [] for country in request.form.lists(): countries_selected.append(country[1][0]) # GET request returns all countries for initial page load else: figures = return_figures() countries_selected = [] for country in country_codes: countries_selected.append(country[1]) # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figuresJSON, all_countries=country_codes, countries_selected=countries_selected)
def index(): # List of countries to use with the dropdown menu country_codes = [('Canada', 'CAN'), ('United States', 'USA'), ('Brazil', 'BRA'), ('France', 'FRA'), ('India', 'IND'), ('Italy', 'ITA'), ('Germany', 'DEU'), ('United Kingdom', 'GBR'), ('China', 'CHN'), ('Japan', 'JPN'), ('Russia', 'RUS'), ('Turkmenistan', 'TKM')] # Parse the POST request countries list if (request.method == 'POST') and request.form: figures = return_figures(request.form) countries_selected = [] for country in request.form.lists(): countries_selected.append(country[1][0]) # GET request returns all countries for initial page load else: figures = return_figures() countries_selected = [] for country in country_codes: countries_selected.append(country[1]) # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figuresJSON, all_countries = country_codes, countries_selected = countries_selected)
def index(): default_county = ['United_States_of_America'] # get the dataset dataset = get_dataset() # prepare the map dataset map_data = set_map_data(dataset) five_top_countries, country_codes = get_the_top(map_data) # to get the five top countries five_top_countries = [country for country, code in five_top_countries] dates = [dataset.index.min(), dataset.index.max()] five_top_df = filter_data(dataset, country_name=five_top_countries, date=dates) # to get the initial charts (map and the five top countries) figures = return_figures(map_data, five_top_df) # Parse the POST request country list if (request.method == 'POST') and request.form: # the user selected country filter_df = filter_data(dataset, country_name=list(request.form.values()), date=dates) user_selected_figure = return_figures(map_data, filter_df) default_county = list(request.form.values()) else: # the default user selected country chart filter_df = filter_data(dataset, country_name=default_county, date=dates) user_selected_figure = return_figures(map_data, filter_df) # to add the default user selected charts to into figures for figure in user_selected_figure: figures.append(figure) # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figuresJSON, all_countries=country_codes, default_county=default_county)
def PM25(): figures = return_figures('PM25') ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('PM25.html', ids=ids, figuresJSON=figuresJSON)
def index(): try: if request.method == 'POST': figures = return_figures( request.form['portfolio'], request.form['toggle']) #get values from inputs as arguments else: figures = return_figures() except: figures = return_figures() # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figuresJSON)
def index(): figures = return_figures() # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template("index.html", ids=ids, figuresJSON=figuresJSON)
def index(): figures = return_figures() # Plot ids for HTML id tag ids = [f'figure-{i}' for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for JS in HTML template figures_json = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figures_json)
def index(): # figures info figures = return_figures() # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figuresJSON)
def index(): # List of countries for filter country_codes = [ 'Costa Rica', 'Panama', 'Nicaragua', 'Guatemala', 'Honduras', 'El Salvador', 'US', 'Mexico', 'Canada', 'Colombia', 'Chile', 'Argentina', 'Venezuela', 'Ecuador', 'Uruguay', 'Brazil', 'Peru', 'India', 'Italy', 'Spain', 'France', 'Germany', 'United Kingdom', 'Russia' ] # Parse the POST request countries list if (request.method == 'POST') and request.form: figures = return_figures(request.form) countries_selected = [] for country in request.form.lists(): countries_selected.append(country) # GET request returns all countries for initial page load else: figures = return_figures() countries_selected = [] for country in country_codes: countries_selected.append(country) # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figuresJSON, all_countries=country_codes, countries_selected=countries_selected)
def index(): filepath = "/app/robotapp/robot_data.csv" df = prepare_data(filepath) figures = return_figures(df) # plot ids for the html id tag ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)] # Convert the plotly figures to JSON for javascript in html template figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder) return render_template('index.html', ids=ids, figuresJSON=figuresJSON)
#import plotly.graph_objs as go # this worked instead from plotly.graph_objs import * import plotly.plotly as py import re #from sklearn.externals import joblib import pickle import sqlalchemy from sqlalchemy import create_engine from files.essential import tokenize import wrangling_scripts.wrangle_data from wrangling_scripts.wrangle_data import return_figures # index webpage displays cool visuals and receives user input text for model graphs, model, df_data = return_figures() @app.route('/') @app.route('/index') def index(): '''prepare plotly graphs and layout to dump to json for html frontend use Args: None Returns: None '''