SHARE
TWEET

dash 2/3

a guest Feb 14th, 2020 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import dash
  5. import dash_core_components as dcc
  6. import dash_html_components as html
  7.  
  8. import plotly.graph_objs as go
  9.  
  10. import pandas as pd
  11.  
  12. #задаем данные для отрисовки
  13. games_raw = pd.read_csv('/datasets/games_full.csv')
  14. games_raw['Year_of_Release'] = pd.to_datetime(games_raw['Year_of_Release'])
  15.  
  16. #формируем данные для отчета
  17. games_grouped = (games_raw.groupby(['Genre', 'Year_of_Release'])
  18.                           .agg({'Name':'count'})
  19.                           .reset_index()
  20.                           .rename(columns = {'Name':'Games Released'})
  21.                 )
  22.  
  23. #формируем графики для отрисовки
  24. data = []
  25. for genre in games_grouped['Genre'].unique():
  26.     current = games_grouped.query('Genre == @genre')
  27.     data += [go.Scatter(x = current['Year_of_Release'],
  28.                         y = current['Games Released'],
  29.                         mode = 'lines',
  30.                         stackgroup = True,
  31.                         name = genre)]
  32.  
  33. #задаем лейаут
  34. external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
  35. app = dash.Dash(__name__, external_stylesheets=external_stylesheets,compress=False)
  36. app.layout = html.Div(children=[  
  37.    
  38.     #формируем html
  39.     html.H1(children = 'Выпуск игр по годам'),
  40.  
  41.     dcc.Graph(
  42.         figure = {'data': data,
  43.                   'layout': go.Layout(xaxis = {'title': 'Год'},
  44.                                       yaxis = {'title': 'Выпущенные игры'})
  45.                  },
  46.         id = 'games_by_year'
  47.     ),      
  48.  
  49. ])
  50.  
  51. #описываем логику дашборда
  52. if __name__ == '__main__':
  53.     app.run_server(host='0.0.0.0', port=3000)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top