Esempio n. 1
0
def gen_sunburst(clicks, yearpick, grouppicker, countrypick, stylepick):
    if clicks:
        if isinstance(yearpick, str):
            filtered_byyear = popAgeGroup()[popAgeGroup()['time'].isin(
                [yearpick])]
        else:
            filtered_byyear = popAgeGroup()[popAgeGroup()['time'].isin(
                yearpick)]

        if isinstance(grouppicker, str):
            filter_bygroup = filtered_byyear[filtered_byyear['indic_de'].isin(
                [grouppicker])]
        else:
            filter_bygroup = filtered_byyear[filtered_byyear['indic_de'].isin(
                grouppicker)]

        if isinstance(countrypick, str):
            filter_bycountry = filter_bygroup[filter_bygroup['geo'].isin(
                [countrypick])]
        else:
            filter_bycountry = filter_bygroup[filter_bygroup['geo'].isin(
                countrypick)]
        ''''PX is being used rather then go.Sunburst due to px requirements fitting more easily with our
         requirements as go.Scatter required all possible parent relation ships to be given '''
        sunburstout = (px.sunburst(filter_bycountry,
                                   path=['time', 'geo', 'indic_de'],
                                   values='values',
                                   height=800,
                                   template=stylepick))
        return sunburstout
Esempio n. 2
0
def update_graph(picked_year, xaxis_name, yaxis_name):
    filtered_df = popAgeGroup()[popAgeGroup()['time'] == picked_year]

    traces = []

    for country_name in filtered_df['geo'].unique():
        df_by_country = filtered_df[filtered_df['geo'] == country_name]
        traces.append(
            go.Scatter(x=df_by_country[xaxis_name],
                       y=df_by_country[yaxis_name],
                       mode='markers',
                       marker={
                           'size': 15,
                           'opacity': 0.5,
                           'line': {
                               'width': 0.5,
                               'color': 'white'
                           }
                       }))
    return {
        'data':
        traces,
        'layout':
        go.Layout(title='population from groups',
                  xaxis={'title': xaxis_name},
                  yaxis={'title': yaxis_name},
                  hovermode='closest'),
    }
Esempio n. 3
0
def gen_table(clicks, yearpick, grouppicker, countrypick):
    """filtering by year down to group down to country selected"""
    if clicks:
        if isinstance(yearpick, str):
            filtered_by_year = popAgeGroup()[popAgeGroup()['time'].isin(
                [yearpick])]
        else:
            filtered_by_year = popAgeGroup()[popAgeGroup()['time'].isin(
                yearpick)]

        if isinstance(grouppicker, str):
            filter_by_group = filtered_by_year[
                filtered_by_year['indic_de'].isin([grouppicker])]
        else:
            filter_by_group = filtered_by_year[
                filtered_by_year['indic_de'].isin(grouppicker)]

        if isinstance(countrypick, str):
            filter_by_country = filter_by_group[filter_by_group['geo'].isin(
                [countrypick])]
        else:
            filter_by_country = filter_by_group[filter_by_group['geo'].isin(
                countrypick)]

            table_out = dt.DataTable(
                data=filter_by_country.to_dict('records'),
                columns=[{
                    'name': i,
                    'id': i
                } for i in filter_by_country.columns],
                fixed_rows={'headers': True},
                page_size=30,
                style_table={
                    'height': '300px',
                    'overflowY': 'auto'
                },
                style_header={
                    'backgroundColor': 'white',
                    'fontWeight': 'bold'
                },
                export_format='xlsx',
                export_headers='display',
            )

            return table_out
Esempio n. 4
0
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
from apps.navbar import Navbar
from app import app
from apps.eurostatapi import popAgeGroup
import plotly.graph_objs as go
import plotly.express as px

nav = Navbar()

year_options = []
for time in popAgeGroup()['time'].unique():
    year_options.append({'label': str(time), 'value': time})

features = popAgeGroup().columns

body = html.Div([
    html.Div([
        html.H3('Population'),
        html.Div(id='app-2-display-value'),
        dcc.Link('Go to App 1', href='/apps/page1'),
        html.Div([
            html.Div([
                dcc.Dropdown(id='xaxis',
                             options=[{
                                 'label': i,
                                 'value': i
                             } for i in features],
                             value='indic_de')
Esempio n. 5
0
import time
import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
import plotly.express as px
import plotly.graph_objs as go
from dash.dependencies import Input, Output, State
from apps.eurostatapi import popAgeGroup
from app import app
from apps.navbar import Navbar

nav = Navbar()

body = html.H4('Under construction')

features = popAgeGroup().columns


def PageLayOut():
    layout = html.Div([nav, body])
    return layout
Esempio n. 6
0
def generate_graphs(n_clicks, yearpick, xaxis_name, yaxis_name, grouppicker,
                    stylepick, countrypick):
    if not n_clicks:
        # generate empty graphs when app loads
        return {
            k: go.Figure(data=[])
            for k in ["scatter", "pie", 'bar', 'sun']
        }
    """isinstance used due to a dropdown single item is a string not a list object and requires to be given []"""
    """to present is as a list for .isin to read"""

    if n_clicks:
        if isinstance(yearpick, str):
            filtered_year = popAgeGroup()[popAgeGroup()['time'].isin(
                [yearpick])]
        else:
            filtered_year = popAgeGroup()[popAgeGroup()['time'].isin(yearpick)]

        if isinstance(grouppicker, str):
            filtered_group = filtered_year[filtered_year['indic_de'].isin(
                [grouppicker])]
        else:
            filtered_group = filtered_year[filtered_year['indic_de'].isin(
                grouppicker)]

        if isinstance(countrypick, str):
            filtered_country = filtered_group[filtered_group['geo'].isin(
                [countrypick])]
        else:
            filtered_country = filtered_group[filtered_group['geo'].isin(
                countrypick)]

    traces = []
    traces2 = []
    traces3 = []

    for country_name in filtered_country['geo'].unique():
        df_by_country = filtered_country[filtered_country['geo'] ==
                                         country_name]
        (go.Figure(
            traces3.append(
                go.Bar(x=df_by_country[df_by_country['geo'] ==
                                       country_name]['time'],
                       y=df_by_country[df_by_country['geo'] == country_name]
                       ['values'],
                       textposition='auto',
                       name=country_name,
                       text=df_by_country['indic_de'],
                       hoverinfo='name+text+x+y'))))
        """generating the scatter plot"""
        go.Figure(
            traces.append(
                go.Scatter(x=df_by_country[xaxis_name],
                           y=df_by_country[yaxis_name],
                           mode='markers',
                           marker={
                               'size': 14,
                               'opacity': 0.5,
                               'line': {
                                   'width': 1
                               },
                           },
                           name=country_name,
                           text=df_by_country['time'],
                           hoverinfo='x+y+text')))
    """generating the Pie chart"""
    (go.Figure(
        traces2.append(
            go.Pie(name="pop",
                   values=filtered_country[yaxis_name],
                   labels=filtered_country[xaxis_name],
                   textinfo='value+label'))))
    ''''filling pie figure with data and layout'''
    pie = {
        'data':
        traces2,
        'layout':
        go.Layout(
            title='% population from groups {} in the year {} '.format(
                grouppicker, yearpick),
            template=stylepick,
            height=800,
        )
    }
    ''''filling scatter figure with data and layout'''
    scatter = {
        'data':
        traces,
        'layout':
        go.Layout(title='% population from groups {} in the year {} '.format(
            grouppicker, yearpick),
                  xaxis={'title': xaxis_name},
                  yaxis={'title': yaxis_name},
                  hoverlabel=dict(bgcolor="white", font_size=16),
                  template=stylepick,
                  hovermode='closest',
                  height=800,
                  autosize=True),
    }
    ''''filling bar figure with data and layout'''
    bar = {
        'data':
        traces3,
        'layout':
        go.Layout(title='% population from groups {} in the year {} '.format(
            grouppicker, yearpick),
                  xaxis={'title': 'year'},
                  yaxis={'title': '% of population'},
                  template=stylepick,
                  hoverlabel=dict(bgcolor="white", font_size=16),
                  hovermode='closest',
                  height=800)
    }

    # save figures in a dictionary for sending to the dcc.Store
    return {"pie": pie, "scatter": scatter, "bar": bar}
Esempio n. 7
0
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
import plotly.express as px
import plotly.graph_objs as go
from dash.dependencies import Input, Output, State
import dash_table as dt
from apps.eurostatapi import popAgeGroup
from app import app
from apps.navbar import Navbar

nav = Navbar()
'''used to create dropdown menues'''
year_options = []
for time in popAgeGroup()['time'].unique():
    year_options.append({'label': str(time), 'value': time})

group_options = []
for group in popAgeGroup()['indic_de'].unique():
    group_options.append({'label': str(group), 'value': group})

country_options = []
for country in popAgeGroup()['geo'].unique():
    country_options.append({'label': str(country), 'value': country})

features = popAgeGroup().columns

body = dbc.Container(
    [
        dcc.Store(id="store"),