import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import numpy as np
import pandas as pd
import plotly.graph_objs as go
import plotly.express as px
import plotly.io as pio
from plotly.colors import n_colors
from plotly.subplots import make_subplots
################################
df = pd.read_csv(‘movies.csv’, encoding = “ISO-8859-1”)
###################################
df.columns = df.columns.str.capitalize()
###################### APP ############################
app = dash.Dash(name)
app.layout = html.Div([
html.Div([
dcc.Graph(id = 'our_graph')
],className = 'nine columns'),
html.Div([
html.Br(),
html.Label(['Choose Country / Genre / Company:'],style={'font-weight': 'bold', "text-align": "center"}),
dcc.Dropdown(id = 'country_drop',
options = [{'label':country, 'value':country} for country in df['Country'].unique()],
value = 'USA',
multi = False,
disabled=False,
clearable=True,
searchable=True,
placeholder='Choose Country...',
className='form-dropdown',
style={'width':"90%"},
persistence='string',
persistence_type='memory'),
dcc.Dropdown(id= 'genre_drop',
options = [{'label': genre, 'value' : genre} for genre in df['Genre'].unique()],
value = 'Drama',
multi = False,
disabled=False,
clearable=True,
searchable=True,
placeholder='Choose Genre..',
className='form-dropdown',
style={'width':"90%"},
persistence='string',
persistence_type='memory'),
dcc.Dropdown(id = 'company_drop',
options = [{'label':company, 'value':company} for company in df['Company'].unique()],
value = 'Paramount Pictures',
multi = False,
disabled=False,
clearable=True,
searchable=True,
placeholder='Choose Company..',
className='form-dropdown',
style={'width':"90%"},
persistence='string',
persistence_type='memory'),
],className='three columns')
])
####################Callbacks#######################
@app.callback(
dash.dependencies.Output(‘our_graph’, ‘figure’),
[dash.dependencies.Input(“company_drop”, “value”),
dash.dependencies.Input(“country_drop”, “value”),
dash.dependencies.Input(“genre_drop”, “value”)
]
)
def plots(country, genre,company):
new_df = df.loc[(df[‘Country’] == country) & (df[‘Genre’] == genre) & (df[‘Company’] == company)]
revenue_df = new_df.groupby(by = [‘Year’])[‘Gross’,‘Budget’].sum()
fig = px.line(revenue_df, x=revenue_df.index, y=revenue_df.columns, title = ‘Which Country has the highest revenue by category?’,
labels=dict(x=“Year”, y= ‘Amount of $ in billions’))
return fig
#Run App
if name == ‘main’:
app.run_server(debug=False)