# install required packages
!pip install jupyter_dash==0.4.0
!pip install pandas
!pip install openpyxl
# code chunk to import necessary libraries
from jupyter_dash import JupyterDash
from dash import dcc, html
from dash.dependencies import Input, Output
from plotly import data
import plotly.express as px
import pandas as pd
# read in most popular streaming service data
pop_data = pd.read_excel(
"statistic_id1035628_most-in-demand-video-streaming-services-worldwide-2020-by-share-of-demand.xlsx",
sheet_name=1,
skiprows=5,
usecols="B:D",
header = None,
)
print(pop_data)
# create horizontal bar plot for pop_data dataset
pop_plot = px.bar(pop_data, x=2, y=1, orientation='h',
hover_data=[1, 2],
height=400,
title='Most popular video streaming service based on share of audience demand for digital originals worldwide in 2020',
labels={
"2": "Audience demand share (%)",
"1": ""
})
print(pop_data)
pop_plot.show()
# read in most popular US streaming service data
us_pop_data = pd.read_excel(
"statistic_id910875_leading-us-video-streaming-services-2019-by-monthly-average-users.xlsx",
sheet_name=1,
skiprows=5,
usecols="B:C",
header = None,
)
print(us_pop_data)
# create horizontal bar plot for us_pop_data dataset
us_pop_plot = px.bar(us_pop_data, x=2, y=1, orientation='h',
hover_data=[1, 2],
height=400,
title='Most popular video streaming services in the United States as of September 2019, by monthly average users (in millions)',
labels={
"2": "Number of users (millions)",
"1": ""
})
print(us_pop_data)
us_pop_plot.show()
# read in most viewed tv show per year in UK
uk_show_data = pd.read_excel(
"statistic_id1169502_most-viewed-television-program-every-year-in-the-united-kingdom--uk--2000-2019.xlsx",
sheet_name=1,
skiprows=5,
usecols="B:C",
header = None,
)
print(uk_show_data)
# create horizontal bar plot for us_pop_data dataset
uk_show_plot = px.bar(
uk_show_data,
x=2,
y=1,
orientation="h",
hover_data=[1, 2],
title="Viewing figures for the most watched television program of each year in the United Kingdom (UK) from 2000 to 2019 (in millions)",
labels={"2": "Audience (millions)", "1": ""},
)
print(uk_show_data)
uk_show_plot.show()
# read in digital video viewers in UK
uk_digital_data = pd.read_excel(
"statistic_id193959_digital-video-viewers-in-the-united-kingdom--uk--2012-2019.xlsx",
sheet_name=1,
skiprows=5,
usecols="B:C",
header = None,
)
print(uk_digital_data)
# create horizontal bar plot for uk_digital_plot dataset
uk_digital_plot = px.bar(
uk_digital_data,
x=2,
y=1,
orientation="h",
hover_data=[1, 2],
title="Digital video viewers in the United Kingdom from 2012 to 2019 (in millions)",
labels={"2": "Viewers (millions)", "1": ""},
)
print(uk_digital_data)
uk_digital_plot.show()
# read in IMDB TV audience US data
us_imdb_data = pd.read_excel(
"statistic_id1128393_imdb-tv-audience-us-2020-by-generation.xlsx",
sheet_name=1,
skiprows=5,
usecols="B:D",
header = None,
)
print(us_imdb_data)
# create horizontal bar plot for us_imdb_data dataset
us_imdb_plot = px.bar(
us_imdb_data,
x=2,
y=1,
orientation="h",
hover_data=[1, 2],
title="Share of adults who used IMDB TV in the last year in the United States as of February 2020, by generation",
labels={"2": "Share of respondents (%)", "1": ""},
)
print(us_imdb_data)
us_imdb_plot.show()
# read in video watching by device in GB data
gb_device_data = pd.read_excel(
"statistic_id289079_online-video-watching-penetration-in-great-britain-2020-by-device.xlsx",
sheet_name=1,
skiprows=4,
usecols="B:H",
header = 0,
)
print(gb_device_data)
# going to need to restructure the data from wide to long
gb_device_data = gb_device_data.drop("Unnamed: 7", 1)
gb_device_data = pd.melt(
gb_device_data, id_vars=["Unnamed: 1"], var_name="device", value_name="value"
)
# now create a grouped plot
gb_device_plot = px.bar(
gb_device_data,
y="value",
x="Unnamed: 1",
color="device",
barmode="group",
title="Penetration of online video watching in Great Britain in 2020, by device",
labels={"value": "Share of respondents (%)", "Unnamed: 1": ""},
)
gb_device_plot.show()
# read in subscriber market share data
subscribers_data = pd.read_excel(
"statistic_id1052803_svod-platforms-subscriber-market-share-worldwide-in-2024.xlsx",
sheet_name=1,
skiprows=5,
usecols="B:D",
header = None,
)
print(subscribers_data)
# create horizontal bar plot for subscribers_data plot
subscribers_plot = px.bar(
subscribers_data,
x=2,
y=1,
orientation="h",
hover_data=[1, 2],
title="Estimated subscriber market share of selected SVOD services worldwide in 2024",
labels={"2": "Subscriber market share (%)", "1": ""},
)
print(subscribers_data)
subscribers_plot.show()
app = JupyterDash(__name__)
app.layout = html.Div(
[
html.P("Select plot:"),
dcc.Dropdown(
id="plot",
value="pop_plot",
options=[
{
"value": "pop_plot",
"label": "Most popular video streaming service based on share of audience demand for digital originals worldwide in 2020",
},
{
"value": "us_pop_plot",
"label": "Most popular video streaming services in the United States as of September 2019, by monthly average users (in millions)",
},
{
"value": "uk_show_plot",
"label": "Viewing figures for the most watched television program of each year in the United Kingdom (UK) from 2000 to 2019 (in millions)",
},
{
"value": "uk_digital_plot",
"label": "Digital video viewers in the United Kingdom from 2012 to 2019 (in millions)",
},
{
"value": "us_imdb_plot",
"label": "Share of adults who used IMDB TV in the last year in the United States as of February 2020, by generation",
},
{
"value": "gb_device_plot",
"label": "Penetration of online video watching in Great Britain in 2020, by device",
},
{
"value": "subscribers_plot",
"label": "Estimated subscriber market share of selected SVOD services worldwide in 2024",
},
],
clearable=False,
),
dcc.Graph(id="charts"),
]
)
@app.callback(Output("charts", "figure"), Input("plot", "value"))
def generate_chart(plot):
if plot == "pop_plot":
fig = pop_plot
if plot == "us_pop_plot":
fig = us_pop_plot
if plot == "uk_show_plot":
fig = uk_show_plot
if plot == "uk_digital_plot":
fig = uk_digital_plot
if plot == "us_imdb_plot":
fig = us_imdb_plot
if plot == "gb_device_plot":
fig = gb_device_plot
if plot == "subscribers_plot":
fig = subscribers_plot
return fig
app.run_server(
mode="external",
port=8080,
host="0.0.0.0",
dev_tools_ui=True,
dev_tools_hot_reload=True,
threaded=True,
)