# install required packages
!pip install jupyter_dash==0.4.0
!pip install pandas
!pip install openpyxl
Requirement already satisfied: jupyter_dash==0.4.0 in /root/venv/lib/python3.7/site-packages (0.4.0)
Requirement already satisfied: dash in /root/venv/lib/python3.7/site-packages (from jupyter_dash==0.4.0) (2.0.0)
Requirement already satisfied: ipython in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from jupyter_dash==0.4.0) (7.28.0)
Requirement already satisfied: ipykernel in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from jupyter_dash==0.4.0) (5.5.5)
Requirement already satisfied: flask in /root/venv/lib/python3.7/site-packages (from jupyter_dash==0.4.0) (2.0.2)
Requirement already satisfied: requests in /shared-libs/python3.7/py/lib/python3.7/site-packages (from jupyter_dash==0.4.0) (2.26.0)
Requirement already satisfied: retrying in /root/venv/lib/python3.7/site-packages (from jupyter_dash==0.4.0) (1.3.3)
Requirement already satisfied: ansi2html in /root/venv/lib/python3.7/site-packages (from jupyter_dash==0.4.0) (1.6.0)
Requirement already satisfied: dash-table==5.0.0 in /root/venv/lib/python3.7/site-packages (from dash->jupyter_dash==0.4.0) (5.0.0)
Requirement already satisfied: dash-html-components==2.0.0 in /root/venv/lib/python3.7/site-packages (from dash->jupyter_dash==0.4.0) (2.0.0)
Requirement already satisfied: plotly>=5.0.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from dash->jupyter_dash==0.4.0) (5.3.1)
Requirement already satisfied: flask-compress in /root/venv/lib/python3.7/site-packages (from dash->jupyter_dash==0.4.0) (1.10.1)
Requirement already satisfied: dash-core-components==2.0.0 in /root/venv/lib/python3.7/site-packages (from dash->jupyter_dash==0.4.0) (2.0.0)
Requirement already satisfied: Werkzeug>=2.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from flask->jupyter_dash==0.4.0) (2.0.2)
Requirement already satisfied: Jinja2>=3.0 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from flask->jupyter_dash==0.4.0) (3.0.2)
Requirement already satisfied: itsdangerous>=2.0 in /root/venv/lib/python3.7/site-packages (from flask->jupyter_dash==0.4.0) (2.0.1)
Requirement already satisfied: click>=7.1.2 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from flask->jupyter_dash==0.4.0) (8.0.3)
Requirement already satisfied: importlib-metadata in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from click>=7.1.2->flask->jupyter_dash==0.4.0) (4.8.1)
Requirement already satisfied: MarkupSafe>=2.0 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from Jinja2>=3.0->flask->jupyter_dash==0.4.0) (2.0.1)
Requirement already satisfied: six in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from plotly>=5.0.0->dash->jupyter_dash==0.4.0) (1.16.0)
Requirement already satisfied: tenacity>=6.2.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from plotly>=5.0.0->dash->jupyter_dash==0.4.0) (8.0.1)
Requirement already satisfied: brotli in /root/venv/lib/python3.7/site-packages (from flask-compress->dash->jupyter_dash==0.4.0) (1.0.9)
Requirement already satisfied: typing-extensions>=3.6.4 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from importlib-metadata->click>=7.1.2->flask->jupyter_dash==0.4.0) (3.10.0.2)
Requirement already satisfied: zipp>=0.5 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from importlib-metadata->click>=7.1.2->flask->jupyter_dash==0.4.0) (3.6.0)
Requirement already satisfied: traitlets>=4.1.0 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipykernel->jupyter_dash==0.4.0) (4.3.3)
Requirement already satisfied: tornado>=4.2 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipykernel->jupyter_dash==0.4.0) (6.1)
Requirement already satisfied: jupyter-client in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipykernel->jupyter_dash==0.4.0) (6.1.12)
Requirement already satisfied: decorator in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipython->jupyter_dash==0.4.0) (5.1.0)
Requirement already satisfied: setuptools>=18.5 in /root/venv/lib/python3.7/site-packages (from ipython->jupyter_dash==0.4.0) (58.1.0)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipython->jupyter_dash==0.4.0) (3.0.20)
Requirement already satisfied: pickleshare in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipython->jupyter_dash==0.4.0) (0.7.5)
Requirement already satisfied: backcall in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipython->jupyter_dash==0.4.0) (0.2.0)
Requirement already satisfied: jedi>=0.16 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipython->jupyter_dash==0.4.0) (0.17.2)
Requirement already satisfied: matplotlib-inline in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipython->jupyter_dash==0.4.0) (0.1.3)
Requirement already satisfied: pexpect>4.3 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipython->jupyter_dash==0.4.0) (4.8.0)
Requirement already satisfied: pygments in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from ipython->jupyter_dash==0.4.0) (2.10.0)
Requirement already satisfied: parso<0.8.0,>=0.7.0 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from jedi>=0.16->ipython->jupyter_dash==0.4.0) (0.7.1)
Requirement already satisfied: ptyprocess>=0.5 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from pexpect>4.3->ipython->jupyter_dash==0.4.0) (0.7.0)
Requirement already satisfied: wcwidth in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython->jupyter_dash==0.4.0) (0.2.5)
Requirement already satisfied: ipython-genutils in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from traitlets>=4.1.0->ipykernel->jupyter_dash==0.4.0) (0.2.0)
Requirement already satisfied: python-dateutil>=2.1 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from jupyter-client->ipykernel->jupyter_dash==0.4.0) (2.8.2)
Requirement already satisfied: jupyter-core>=4.6.0 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from jupyter-client->ipykernel->jupyter_dash==0.4.0) (4.7.1)
Requirement already satisfied: pyzmq>=13 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from jupyter-client->ipykernel->jupyter_dash==0.4.0) (22.3.0)
Requirement already satisfied: idna<4,>=2.5 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from requests->jupyter_dash==0.4.0) (3.3)
Requirement already satisfied: certifi>=2017.4.17 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests->jupyter_dash==0.4.0) (2021.10.8)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests->jupyter_dash==0.4.0) (1.26.7)
Requirement already satisfied: charset-normalizer~=2.0.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests->jupyter_dash==0.4.0) (2.0.7)
WARNING: You are using pip version 21.2.4; however, version 21.3 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
Requirement already satisfied: pandas in /shared-libs/python3.7/py/lib/python3.7/site-packages (1.2.5)
Requirement already satisfied: pytz>=2017.3 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pandas) (2021.3)
Requirement already satisfied: numpy>=1.16.5 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pandas) (1.19.5)
Requirement already satisfied: python-dateutil>=2.7.3 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from pandas) (2.8.2)
Requirement already satisfied: six>=1.5 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas) (1.16.0)
WARNING: You are using pip version 21.2.4; however, version 21.3 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
Requirement already satisfied: openpyxl in /root/venv/lib/python3.7/site-packages (3.0.9)
Requirement already satisfied: et-xmlfile in /root/venv/lib/python3.7/site-packages (from openpyxl) (1.1.0)
WARNING: You are using pip version 21.2.4; however, version 21.3 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
# 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)
1 2 3
0 Netflix 53.5 in %
1 Amazon Prime Video 12.6 in %
2 Hulu 6.3 in %
3 Apple TV+ 3.9 in %
4 HBO Max 3.6 in %
5 Disney+ 3.6 in %
6 CBS All Access 3.5 in %
7 Other 13.1 in %
# 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()
1 2 3
0 Netflix 53.5 in %
1 Amazon Prime Video 12.6 in %
2 Hulu 6.3 in %
3 Apple TV+ 3.9 in %
4 HBO Max 3.6 in %
5 Disney+ 3.6 in %
6 CBS All Access 3.5 in %
7 Other 13.1 in %
# 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)
1 2
0 YouTube 163.75
1 Netflix 46.55
2 Hulu 26.48
3 Amazon Prime Video 16.46
4 Vimeo 15.06
# 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()
1 2
0 YouTube 163.75
1 Netflix 46.55
2 Hulu 26.48
3 Amazon Prime Video 16.46
4 Vimeo 15.06
# 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)
1 2
0 2019*: Gavin and Stacey 17.92
1 2018: World Cup Croatia v England 20.73
2 2017: Blue Planet 2 14.01
3 2016: The Great British Bake Off 15.90
4 2015: The Great British Bake Off 15.05
5 2014: World Cup Germany v Argentina 14.96
6 2013: New Year's Eve Fireworks 13.53
7 2012: Olympics Closing Ceremony 24.46
8 2011: The Royal Wedding 13.59
9 2010: The X Factor Results 16.55
10 2009: Britain's Got Talent Final Result 18.29
11 2008: Wallace and Gromit: A Matter Of Loaf and... 16.15
12 2007: Eastenders 14.38
13 2006: World Cup England v Sweden 18.46
14 2005: Coronation Street 14.36
15 2004: Euros England v Portugal 20.66
16 2003: Coronation Street 19.43
17 2002: Only Fools & Horses 17.40
18 2001: Only Fools & Horses 21.35
19 2000: Coronation Street 18.96
# 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()
1 2
0 2019*: Gavin and Stacey 17.92
1 2018: World Cup Croatia v England 20.73
2 2017: Blue Planet 2 14.01
3 2016: The Great British Bake Off 15.90
4 2015: The Great British Bake Off 15.05
5 2014: World Cup Germany v Argentina 14.96
6 2013: New Year's Eve Fireworks 13.53
7 2012: Olympics Closing Ceremony 24.46
8 2011: The Royal Wedding 13.59
9 2010: The X Factor Results 16.55
10 2009: Britain's Got Talent Final Result 18.29
11 2008: Wallace and Gromit: A Matter Of Loaf and... 16.15
12 2007: Eastenders 14.38
13 2006: World Cup England v Sweden 18.46
14 2005: Coronation Street 14.36
15 2004: Euros England v Portugal 20.66
16 2003: Coronation Street 19.43
17 2002: Only Fools & Horses 17.40
18 2001: Only Fools & Horses 21.35
19 2000: Coronation Street 18.96
# 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)
1 2
0 2012 32.6
1 2013 34.5
2 2014 37.4
3 2015 39.5
4 2016* 41.3
5 2017* 42.8
6 2018* 43.9
7 2019* 45.6
# 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()
1 2
0 2012 32.6
1 2013 34.5
2 2014 37.4
3 2015 39.5
4 2016* 41.3
5 2017* 42.8
6 2018* 43.9
7 2019* 45.6
# 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)
1 2 3
0 Gen Z 8 in %
1 Millennials 3 in %
2 Gen X 5 in %
3 Baby boomer 4 in %
# 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()
1 2 3
0 Gen Z 8 in %
1 Millennials 3 in %
2 Gen X 5 in %
3 Baby boomer 4 in %
# 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)
Unnamed: 1 Smartphone Tablet \
0 Any content 59 32
1 On demand TV services 22 15
2 Video content through subscription services 26 15
3 Videos or clips on video sharing platforms 56 26
Laptop/Desktop computer Smart TV Games console Unnamed: 7
0 39 54 8 in %
1 19 45 5 in %
2 20 41 6 in %
3 32 17 4 in %
# 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)
1 2 3
0 Netflix 23 in %
1 Amazon Prime Video 13 in %
2 Disney+ 8 in %
3 Apple TV+ 1 in %
# 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()
1 2 3
0 Netflix 23 in %
1 Amazon Prime Video 13 in %
2 Disney+ 8 in %
3 Apple TV+ 1 in %
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,
)
Dash app running on http://0.0.0.0:8080/