Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Teguh010/b7b98335fe6ec24dca1a6a7ddf84830f to your computer and use it in GitHub Desktop.
Save Teguh010/b7b98335fe6ec24dca1a6a7ddf84830f to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a><img src=\"https://ibm.box.com/shared/static/ugcqz6ohbvff804xp84y4kqnvvk3bq1g.png\" width=\"200\" align=\"center\"></a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1>Analyzing US Economic Data and Building a Dashboard </h1>\n",
"<h2>Description</h2>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Extracting essential data from a dataset and displaying it is a necessary part of data science; therefore individuals can make correct decisions based on the data. In this assignment, you will extract some essential economic indicators from some data, you will then display these economic indicators in a Dashboard. You can then share the dashboard via an URL.\n",
"<p>\n",
"<a href=\"https://en.wikipedia.org/wiki/Gross_domestic_product\"> Gross domestic product (GDP)</a> is a measure of the market value of all the final goods and services produced in a period. GDP is an indicator of how well the economy is doing. A drop in GDP indicates the economy is producing less; similarly an increase in GDP suggests the economy is performing better. In this lab, you will examine how changes in GDP impact the unemployment rate. You will take screen shots of every step, you will share the notebook and the URL pointing to the dashboard.</p>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>Table of Contents</h2>\n",
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
" <ul>\n",
" <li><a href=\"#Section_1\"> Define a Function that Makes a Dashboard </a></li>\n",
" <li><a href=\"#Section_2\">Question 1: Create a dataframe that contains the GDP data and display it</a> </li>\n",
" <li><a href=\"#Section_3\">Question 2: Create a dataframe that contains the unemployment data and display it</a></li>\n",
" <li><a href=\"#Section_4\">Question 3: Display a dataframe where unemployment was greater than 8.5%</a></li>\n",
" <li><a href=\"#Section_5\">Question 4: Use the function make_dashboard to make a dashboard</a></li>\n",
" <li><a href=\"#Section_6\">Question 5: Save the dashboard on IBM cloud and display it</a></li>\n",
" </ul>\n",
"<p>\n",
" Estimated Time Needed: <strong>180 min</strong></p>\n",
"</div>\n",
"\n",
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"Section_1\"> Define Function that Makes a Dashboard </h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will import the following libraries."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: bokeh in /home/jupyterlab/conda/lib/python3.6/site-packages (1.1.0)\n",
"Requirement already satisfied: six>=1.5.2 in /home/jupyterlab/conda/lib/python3.6/site-packages (from bokeh) (1.12.0)\n",
"Requirement already satisfied: PyYAML>=3.10 in /home/jupyterlab/conda/lib/python3.6/site-packages (from bokeh) (5.1)\n",
"Requirement already satisfied: pillow>=4.0 in /home/jupyterlab/conda/lib/python3.6/site-packages (from bokeh) (5.4.1)\n",
"Requirement already satisfied: tornado>=4.3 in /home/jupyterlab/conda/lib/python3.6/site-packages (from bokeh) (6.0.2)\n",
"Requirement already satisfied: Jinja2>=2.7 in /home/jupyterlab/conda/lib/python3.6/site-packages (from bokeh) (2.10.1)\n",
"Requirement already satisfied: python-dateutil>=2.1 in /home/jupyterlab/conda/lib/python3.6/site-packages (from bokeh) (2.8.0)\n",
"Requirement already satisfied: numpy>=1.7.1 in /home/jupyterlab/conda/lib/python3.6/site-packages (from bokeh) (1.15.4)\n",
"Requirement already satisfied: packaging>=16.8 in /home/jupyterlab/conda/lib/python3.6/site-packages (from bokeh) (19.0)\n",
"Requirement already satisfied: MarkupSafe>=0.23 in /home/jupyterlab/conda/lib/python3.6/site-packages (from Jinja2>=2.7->bokeh) (1.1.1)\n",
"Requirement already satisfied: pyparsing>=2.0.2 in /home/jupyterlab/conda/lib/python3.6/site-packages (from packaging>=16.8->bokeh) (2.4.0)\n"
]
}
],
"source": [
"import pandas as pd\n",
"!pip install bokeh\n",
"from bokeh.plotting import figure, output_file, show\n",
"\n",
"from bokeh.io import output_notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this section, we define the function <code>make_dashboard</code>. \n",
"You don't have to know how the function works, you should only care about the inputs. The function will produce a dashboard as well as an html file. You can then use this html file to share your dashboard. If you do not know what an html file is don't worry everything you need to know will be provided in the lab. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def make_dashboard(x, gdp_change, unemployment, title, file_name):\n",
" output_file(file_name)\n",
" output_notebook()\n",
" p = figure(title=title, x_axis_label='year', y_axis_label='%')\n",
" p.line(x.squeeze(), gdp_change.squeeze(), color=\"firebrick\", line_width=4, legend=\"% GDP change\")\n",
" p.line(x.squeeze(), unemployment.squeeze(), line_width=4, legend=\"% unemployed\")\n",
" show(p)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The dictionary <code>links</code> contain the CSV files with all the data. The value for the key <code>GDP</code> is the file that contains the GDP data. The value for the key <code>unemployment</code> contains the unemployment data."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"links={'GDP':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv'}"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"links={'GDP':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv',\\\n",
" 'unemployment':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_unemployment.csv'}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"Section_2\"> Question 1: Create a dataframe that contains the GDP data and display the first five rows of the dataframe.</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the dictionary <code>links</code> and the function <code>pd.read_csv</code> to create a Pandas dataframes that contains the GDP data."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<b>Hint: <code>links[\"GDP\"]</code> contains the path or name of the file.</b>"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# Type your code here\n",
"gdp = pd.read_csv(links[\"GDP\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the method <code>head()</code> to display the first five rows of the GDP data, then take a screen-shot."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>date</th>\n",
" <th>level-current</th>\n",
" <th>level-chained</th>\n",
" <th>change-current</th>\n",
" <th>change-chained</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1948</td>\n",
" <td>274.8</td>\n",
" <td>2020.0</td>\n",
" <td>-0.7</td>\n",
" <td>-0.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1949</td>\n",
" <td>272.8</td>\n",
" <td>2008.9</td>\n",
" <td>10.0</td>\n",
" <td>8.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1950</td>\n",
" <td>300.2</td>\n",
" <td>2184.0</td>\n",
" <td>15.7</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1951</td>\n",
" <td>347.3</td>\n",
" <td>2360.0</td>\n",
" <td>5.9</td>\n",
" <td>4.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1952</td>\n",
" <td>367.7</td>\n",
" <td>2456.1</td>\n",
" <td>6.0</td>\n",
" <td>4.7</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" date level-current level-chained change-current change-chained\n",
"0 1948 274.8 2020.0 -0.7 -0.6\n",
"1 1949 272.8 2008.9 10.0 8.7\n",
"2 1950 300.2 2184.0 15.7 8.0\n",
"3 1951 347.3 2360.0 5.9 4.1\n",
"4 1952 367.7 2456.1 6.0 4.7"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Type your code here\n",
"gdp.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"Section_2\"> Question 2: Create a dataframe that contains the unemployment data. Display the first five rows of the dataframe. </h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the dictionary <code>links</code> and the function <code>pd.read_csv</code> to create a Pandas dataframes that contains the unemployment data."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# Type your code here\n",
"unp = pd.read_csv(links['unemployment'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the method <code>head()</code> to display the first five rows of the GDP data, then take a screen-shot."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>date</th>\n",
" <th>unemployment</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1948</td>\n",
" <td>3.750000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1949</td>\n",
" <td>6.050000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1950</td>\n",
" <td>5.208333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1951</td>\n",
" <td>3.283333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1952</td>\n",
" <td>3.025000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" date unemployment\n",
"0 1948 3.750000\n",
"1 1949 6.050000\n",
"2 1950 5.208333\n",
"3 1951 3.283333\n",
"4 1952 3.025000"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Type your code here\n",
"unp.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"Section_3\">Question 3: Display a dataframe where unemployment was greater than 8.5%. Take a screen-shot.</h3>"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>date</th>\n",
" <th>unemployment</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>1975</td>\n",
" <td>8.475000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>1982</td>\n",
" <td>9.708333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>1983</td>\n",
" <td>9.600000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>61</th>\n",
" <td>2009</td>\n",
" <td>9.283333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>62</th>\n",
" <td>2010</td>\n",
" <td>9.608333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>63</th>\n",
" <td>2011</td>\n",
" <td>8.933333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>64</th>\n",
" <td>2012</td>\n",
" <td>8.075000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" date unemployment\n",
"27 1975 8.475000\n",
"34 1982 9.708333\n",
"35 1983 9.600000\n",
"61 2009 9.283333\n",
"62 2010 9.608333\n",
"63 2011 8.933333\n",
"64 2012 8.075000"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Type your code here\n",
"unp[unp['unemployment'] >=8]\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"Section_4\">Question 4: Use the function make_dashboard to make a dashboard</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this section, you will call the function <code>make_dashboard</code> , to produce a dashboard. We will use the convention of giving each variable the same name as the function parameter."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a new dataframe with the column <code>'date'</code> called <code>x</code> from the dataframe that contains the GDP data."
]
},
{
"cell_type": "code",
"execution_count": 117,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.frame.DataFrame"
]
},
"execution_count": 117,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create your dataframe with column date\n",
"x = gdp[['date']]\n",
"type(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a new dataframe with the column <code>'change-current' </code> called <code>gdp_change</code> from the dataframe that contains the GDP data."
]
},
{
"cell_type": "code",
"execution_count": 118,
"metadata": {},
"outputs": [],
"source": [
"# Create your dataframe with column change-current\n",
"gdp_change = pd.DataFrame(gdp, columns=['change-current'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a new dataframe with the column <code>'unemployment' </code> called <code>unemployment</code> from the dataframe that contains the unemployment data."
]
},
{
"cell_type": "code",
"execution_count": 119,
"metadata": {},
"outputs": [],
"source": [
"unemployment = pd.DataFrame(unp, columns=['unemployment']) # Create your dataframe with column unemployment"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Give your dashboard a string title, and assign it to the variable <code>title</code>"
]
},
{
"cell_type": "code",
"execution_count": 120,
"metadata": {},
"outputs": [],
"source": [
"title = 'Teguh_Dashboard' # Give your dashboard a string title"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, the function <code>make_dashboard</code> will output an <code>.html</code> in your direictory, just like a <code>csv</code> file. The name of the file is <code>\"index.html\"</code> and it will be stored in the varable <code>file_name</code>."
]
},
{
"cell_type": "code",
"execution_count": 121,
"metadata": {},
"outputs": [],
"source": [
"file_name = \"index.html\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Call the function <code>make_dashboard</code> , to produce a dashboard. Assign the parameter values accordingly take a the <b>, take a screen shot of the dashboard and submit it</b>."
]
},
{
"cell_type": "code",
"execution_count": 122,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div class=\"bk-root\">\n",
" <a href=\"https://bokeh.pydata.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
" <span id=\"3cd720ba-42d4-42d9-a019-4ebc292f7438\">Loading BokehJS ...</span>\n",
" </div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function(root) {\n",
" function now() {\n",
" return new Date();\n",
" }\n",
"\n",
" var force = true;\n",
"\n",
" if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n",
" root._bokeh_onload_callbacks = [];\n",
" root._bokeh_is_loading = undefined;\n",
" }\n",
"\n",
" var JS_MIME_TYPE = 'application/javascript';\n",
" var HTML_MIME_TYPE = 'text/html';\n",
" var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
" var CLASS_NAME = 'output_bokeh rendered_html';\n",
"\n",
" /**\n",
" * Render data to the DOM node\n",
" */\n",
" function render(props, node) {\n",
" var script = document.createElement(\"script\");\n",
" node.appendChild(script);\n",
" }\n",
"\n",
" /**\n",
" * Handle when an output is cleared or removed\n",
" */\n",
" function handleClearOutput(event, handle) {\n",
" var cell = handle.cell;\n",
"\n",
" var id = cell.output_area._bokeh_element_id;\n",
" var server_id = cell.output_area._bokeh_server_id;\n",
" // Clean up Bokeh references\n",
" if (id !== undefined) {\n",
" Bokeh.index[id].model.document.clear();\n",
" delete Bokeh.index[id];\n",
" }\n",
"\n",
" if (server_id !== undefined) {\n",
" // Clean up Bokeh references\n",
" var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
" cell.notebook.kernel.execute(cmd, {\n",
" iopub: {\n",
" output: function(msg) {\n",
" var element_id = msg.content.text.trim();\n",
" Bokeh.index[element_id].model.document.clear();\n",
" delete Bokeh.index[element_id];\n",
" }\n",
" }\n",
" });\n",
" // Destroy server and session\n",
" var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
" cell.notebook.kernel.execute(cmd);\n",
" }\n",
" }\n",
"\n",
" /**\n",
" * Handle when a new output is added\n",
" */\n",
" function handleAddOutput(event, handle) {\n",
" var output_area = handle.output_area;\n",
" var output = handle.output;\n",
"\n",
" // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
" if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
" return\n",
" }\n",
"\n",
" var toinsert = output_area.element.find(`.${CLASS_NAME.split(' ')[0]}`);\n",
"\n",
" if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
" toinsert[0].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
" // store reference to embed id on output_area\n",
" output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
" }\n",
" if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
" var bk_div = document.createElement(\"div\");\n",
" bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
" var script_attrs = bk_div.children[0].attributes;\n",
" for (var i = 0; i < script_attrs.length; i++) {\n",
" toinsert[0].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
" }\n",
" // store reference to server id on output_area\n",
" output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
" }\n",
" }\n",
"\n",
" function register_renderer(events, OutputArea) {\n",
"\n",
" function append_mime(data, metadata, element) {\n",
" // create a DOM node to render to\n",
" var toinsert = this.create_output_subarea(\n",
" metadata,\n",
" CLASS_NAME,\n",
" EXEC_MIME_TYPE\n",
" );\n",
" this.keyboard_manager.register_events(toinsert);\n",
" // Render to node\n",
" var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
" render(props, toinsert[0]);\n",
" element.append(toinsert);\n",
" return toinsert\n",
" }\n",
"\n",
" /* Handle when an output is cleared or removed */\n",
" events.on('clear_output.CodeCell', handleClearOutput);\n",
" events.on('delete.Cell', handleClearOutput);\n",
"\n",
" /* Handle when a new output is added */\n",
" events.on('output_added.OutputArea', handleAddOutput);\n",
"\n",
" /**\n",
" * Register the mime type and append_mime function with output_area\n",
" */\n",
" OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
" /* Is output safe? */\n",
" safe: true,\n",
" /* Index of renderer in `output_area.display_order` */\n",
" index: 0\n",
" });\n",
" }\n",
"\n",
" // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
" if (root.Jupyter !== undefined) {\n",
" var events = require('base/js/events');\n",
" var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
"\n",
" if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
" register_renderer(events, OutputArea);\n",
" }\n",
" }\n",
"\n",
" \n",
" if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
" root._bokeh_timeout = Date.now() + 5000;\n",
" root._bokeh_failed_load = false;\n",
" }\n",
"\n",
" var NB_LOAD_WARNING = {'data': {'text/html':\n",
" \"<div style='background-color: #fdd'>\\n\"+\n",
" \"<p>\\n\"+\n",
" \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
" \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
" \"</p>\\n\"+\n",
" \"<ul>\\n\"+\n",
" \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
" \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
" \"</ul>\\n\"+\n",
" \"<code>\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"</code>\\n\"+\n",
" \"</div>\"}};\n",
"\n",
" function display_loaded() {\n",
" var el = document.getElementById(\"3cd720ba-42d4-42d9-a019-4ebc292f7438\");\n",
" if (el != null) {\n",
" el.textContent = \"BokehJS is loading...\";\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" if (el != null) {\n",
" el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
" }\n",
" } else if (Date.now() < root._bokeh_timeout) {\n",
" setTimeout(display_loaded, 100)\n",
" }\n",
" }\n",
"\n",
"\n",
" function run_callbacks() {\n",
" try {\n",
" root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n",
" }\n",
" finally {\n",
" delete root._bokeh_onload_callbacks\n",
" }\n",
" console.info(\"Bokeh: all callbacks have finished\");\n",
" }\n",
"\n",
" function load_libs(js_urls, callback) {\n",
" root._bokeh_onload_callbacks.push(callback);\n",
" if (root._bokeh_is_loading > 0) {\n",
" console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
" return null;\n",
" }\n",
" if (js_urls == null || js_urls.length === 0) {\n",
" run_callbacks();\n",
" return null;\n",
" }\n",
" console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
" root._bokeh_is_loading = js_urls.length;\n",
" for (var i = 0; i < js_urls.length; i++) {\n",
" var url = js_urls[i];\n",
" var s = document.createElement('script');\n",
" s.src = url;\n",
" s.async = false;\n",
" s.onreadystatechange = s.onload = function() {\n",
" root._bokeh_is_loading--;\n",
" if (root._bokeh_is_loading === 0) {\n",
" console.log(\"Bokeh: all BokehJS libraries loaded\");\n",
" run_callbacks()\n",
" }\n",
" };\n",
" s.onerror = function() {\n",
" console.warn(\"failed to load library \" + url);\n",
" };\n",
" console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
" }\n",
" };var element = document.getElementById(\"3cd720ba-42d4-42d9-a019-4ebc292f7438\");\n",
" if (element == null) {\n",
" console.log(\"Bokeh: ERROR: autoload.js configured with elementid '3cd720ba-42d4-42d9-a019-4ebc292f7438' but no matching script tag was found. \")\n",
" return false;\n",
" }\n",
"\n",
" var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.10.min.js\"];\n",
"\n",
" var inline_js = [\n",
" function(Bokeh) {\n",
" Bokeh.set_log_level(\"info\");\n",
" },\n",
" \n",
" function(Bokeh) {\n",
" \n",
" },\n",
" function(Bokeh) {\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n",
" console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n",
" Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n",
" }\n",
" ];\n",
"\n",
" function run_inline_js() {\n",
" \n",
" if ((root.Bokeh !== undefined) || (force === true)) {\n",
" for (var i = 0; i < inline_js.length; i++) {\n",
" inline_js[i].call(root, root.Bokeh);\n",
" }if (force === true) {\n",
" display_loaded();\n",
" }} else if (Date.now() < root._bokeh_timeout) {\n",
" setTimeout(run_inline_js, 100);\n",
" } else if (!root._bokeh_failed_load) {\n",
" console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
" root._bokeh_failed_load = true;\n",
" } else if (force !== true) {\n",
" var cell = $(document.getElementById(\"3cd720ba-42d4-42d9-a019-4ebc292f7438\")).parents('.cell').data().cell;\n",
" cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
" }\n",
"\n",
" }\n",
"\n",
" if (root._bokeh_is_loading === 0) {\n",
" console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
" run_inline_js();\n",
" } else {\n",
" load_libs(js_urls, function() {\n",
" console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n",
" run_inline_js();\n",
" });\n",
" }\n",
"}(window));"
],
"application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n \n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n var NB_LOAD_WARNING = {'data': {'text/html':\n \"<div style='background-color: #fdd'>\\n\"+\n \"<p>\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"</p>\\n\"+\n \"<ul>\\n\"+\n \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n \"<li>use INLINE resources instead, as so:</li>\\n\"+\n \"</ul>\\n\"+\n \"<code>\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"</code>\\n\"+\n \"</div>\"}};\n\n function display_loaded() {\n var el = document.getElementById(\"3cd720ba-42d4-42d9-a019-4ebc292f7438\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n }\n finally {\n delete root._bokeh_onload_callbacks\n }\n console.info(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(js_urls, callback) {\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = js_urls.length;\n for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n var s = document.createElement('script');\n s.src = url;\n s.async = false;\n s.onreadystatechange = s.onload = function() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: all BokehJS libraries loaded\");\n run_callbacks()\n }\n };\n s.onerror = function() {\n console.warn(\"failed to load library \" + url);\n };\n console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.getElementsByTagName(\"head\")[0].appendChild(s);\n }\n };var element = document.getElementById(\"3cd720ba-42d4-42d9-a019-4ebc292f7438\");\n if (element == null) {\n console.log(\"Bokeh: ERROR: autoload.js configured with elementid '3cd720ba-42d4-42d9-a019-4ebc292f7438' but no matching script tag was found. \")\n return false;\n }\n\n var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.10.min.js\"];\n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n \n function(Bokeh) {\n \n },\n function(Bokeh) {\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.10.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.10.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.10.min.css\");\n }\n ];\n\n function run_inline_js() {\n \n if ((root.Bokeh !== undefined) || (force === true)) {\n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }if (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n var cell = $(document.getElementById(\"3cd720ba-42d4-42d9-a019-4ebc292f7438\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n\n }\n\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(js_urls, function() {\n console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));"
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<div class=\"bk-root\">\n",
" <div class=\"bk-plotdiv\" id=\"c829a729-7d5f-4adc-b607-5425784d1fbc\"></div>\n",
"</div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"(function(root) {\n",
" function embed_document(root) {\n",
" var docs_json = {\"b8952c76-e3a2-4450-a039-0b855eedb82d\":{\"roots\":{\"references\":[{\"attributes\":{\"callback\":null,\"column_names\":[\"y\",\"x\"],\"data\":{\"x\":[1948,1949,1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016],\"y\":{\"__ndarray__\":\"AAAAAAAADkAzMzMzMzMYQFVVVVVV1RRARURERERECkA0MzMzMzMIQGdmZmZmZgdA3d3d3d1dFkB4d3d3d3cRQAAAAAAAgBBAMzMzMzMzEUDd3d3d3V0bQM3MzMzMzBVArKqqqqoqFkBERERERMQaQEVERERERBZAEhERERGRFkAiIiIiIqIUQImIiIiICBJAVVVVVVVVDkC5u7u7u7sOQHd3d3d3dwxA7+7u7u7uC0Dv7u7u7u4TQM3MzMzMzBdAZ2ZmZmZmFkDu7u7u7m4TQBIRERERkRZAMzMzMzPzIEDLzMzMzMweQDUzMzMzMxxAREREREREGEBnZmZmZmYXQDUzMzMzsxxAeHd3d3d3HkCqqqqqqmojQDMzMzMzMyNAiYiIiIgIHkBERERERMQcQAAAAAAAABxANTMzMzOzGEB3d3d3d/cVQIiIiIiICBVAd3d3d3d3FkBlZmZmZmYbQHh3d3d39x1AISIiIiKiG0BnZmZmZmYYQN/d3d3dXRZAIyIiIiKiFUBERERERMQTQAAAAAAAABJA393d3d3dEEC5u7u7u7sPQHd3d3d39xJAIyIiIiIiF0B4d3d3d/cXQKyqqqqqKhZAVVVVVVVVFEDv7u7u7m4SQHh3d3d3dxJAMzMzMzMzF0AREREREZEiQHd3d3d3NyNA3t3d3d3dIUBnZmZmZiYgQO/u7u7ubh1AIyIiIiKiGECamZmZmRkVQAAAAAAAgBNA\",\"dtype\":\"float64\",\"shape\":[69]}}},\"id\":\"6e538699-a449-4396-9ab4-86171a3279fb\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"label\":{\"value\":\"% unemployed\"},\"renderers\":[{\"id\":\"4318eae0-2252-4e4a-a47c-2aed93505864\",\"type\":\"GlyphRenderer\"}]},\"id\":\"61e6c0c7-542c-4493-a2b0-fc9a123204b4\",\"type\":\"LegendItem\"},{\"attributes\":{\"source\":{\"id\":\"5dd9cb25-af8e-4b3b-84a8-11c8ebc3558b\",\"type\":\"ColumnDataSource\"}},\"id\":\"907cd5ae-0ff0-42af-a86e-f8fec6f0ec6a\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"764a8115-3a3b-4166-9140-a2c1730401af\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"5aa9ea82-2192-4637-b30b-0c1a89127327\",\"type\":\"ResetTool\"},{\"attributes\":{\"axis_label\":\"year\",\"formatter\":{\"id\":\"764a8115-3a3b-4166-9140-a2c1730401af\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"84dfeaca-31ec-4b2f-a470-c6fdf60ce324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"ec413fca-cea1-4791-995c-8aef33ab58a1\",\"type\":\"BasicTicker\"}},\"id\":\"3b5f9b62-a054-4527-be33-5e01c67ce396\",\"type\":\"LinearAxis\"},{\"attributes\":{\"source\":{\"id\":\"6e538699-a449-4396-9ab4-86171a3279fb\",\"type\":\"ColumnDataSource\"}},\"id\":\"80feb287-65fc-4037-91e9-36d357c9a4a2\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"a8ccbd32-c3e3-44d5-bd54-836fefd383d5\",\"type\":\"SaveTool\"},{\"attributes\":{\"line_color\":{\"value\":\"#1f77b4\"},\"line_width\":{\"value\":4},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7db514b4-f3b2-4622-8717-c7bf6e7e202e\",\"type\":\"Line\"},{\"attributes\":{\"plot\":null,\"text\":\"Teguh_Dashboard\"},\"id\":\"9c7d274a-c341-46f2-8098-e6514a399193\",\"type\":\"Title\"},{\"attributes\":{\"overlay\":{\"id\":\"2522be3d-d7c4-445b-a9c0-521f48f7e0ad\",\"type\":\"BoxAnnotation\"}},\"id\":\"3c9478cb-8239-4771-982a-d814f97a98e5\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"data_source\":{\"id\":\"5dd9cb25-af8e-4b3b-84a8-11c8ebc3558b\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"3e32f35e-9dc1-4428-9075-8b5aad805e9f\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"de6164a1-b071-42af-ad5e-edf9697af198\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"907cd5ae-0ff0-42af-a86e-f8fec6f0ec6a\",\"type\":\"CDSView\"}},\"id\":\"249fd97e-24ae-4267-9e1c-8b81038a2a3b\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data_source\":{\"id\":\"6e538699-a449-4396-9ab4-86171a3279fb\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"7db514b4-f3b2-4622-8717-c7bf6e7e202e\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"ca19e3dd-c7d7-49dd-86e1-3219c7ba86a2\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"80feb287-65fc-4037-91e9-36d357c9a4a2\",\"type\":\"CDSView\"}},\"id\":\"4318eae0-2252-4e4a-a47c-2aed93505864\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis_label\":\"%\",\"formatter\":{\"id\":\"a113adf5-b42c-47b9-a857-4444573e8c6a\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"84dfeaca-31ec-4b2f-a470-c6fdf60ce324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"f94e312a-95d5-4aff-a86a-098ba4d454dd\",\"type\":\"BasicTicker\"}},\"id\":\"c24fb7c3-501f-43d6-9ad9-299cde854155\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"ec413fca-cea1-4791-995c-8aef33ab58a1\",\"type\":\"BasicTicker\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"154d8cac-1dc1-42da-9a7b-9fa2f98287f9\",\"type\":\"PanTool\"},{\"id\":\"db2169bb-ea55-4bfe-8986-1352f4b8d9a6\",\"type\":\"WheelZoomTool\"},{\"id\":\"3c9478cb-8239-4771-982a-d814f97a98e5\",\"type\":\"BoxZoomTool\"},{\"id\":\"a8ccbd32-c3e3-44d5-bd54-836fefd383d5\",\"type\":\"SaveTool\"},{\"id\":\"5aa9ea82-2192-4637-b30b-0c1a89127327\",\"type\":\"ResetTool\"},{\"id\":\"23a26ef1-d23d-4a12-93f9-23c023de227b\",\"type\":\"HelpTool\"}]},\"id\":\"52faf946-4d3e-4d45-8151-3bc1b50bfa73\",\"type\":\"Toolbar\"},{\"attributes\":{\"dimension\":1,\"plot\":{\"id\":\"84dfeaca-31ec-4b2f-a470-c6fdf60ce324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"f94e312a-95d5-4aff-a86a-098ba4d454dd\",\"type\":\"BasicTicker\"}},\"id\":\"9e2756bb-f173-4571-87af-6dcd7bf767e4\",\"type\":\"Grid\"},{\"attributes\":{\"label\":{\"value\":\"% GDP change\"},\"renderers\":[{\"id\":\"249fd97e-24ae-4267-9e1c-8b81038a2a3b\",\"type\":\"GlyphRenderer\"}]},\"id\":\"ab6c671f-def2-457b-894d-f50dda24dbec\",\"type\":\"LegendItem\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"y\",\"x\"],\"data\":{\"x\":[1948,1949,1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016],\"y\":{\"__ndarray__\":\"ZmZmZmZm5r8AAAAAAAAkQGZmZmZmZi9AmpmZmZmZF0AAAAAAAAAYQDMzMzMzM9M/zczMzMzMIUBmZmZmZmYWQAAAAAAAABZAAAAAAAAA+D/NzMzMzMwgQAAAAAAAABBAmpmZmZmZDUCamZmZmZkdQGZmZmZmZhZAmpmZmZmZHUDNzMzMzMwgQDMzMzMzMyNAzczMzMzMFkDNzMzMzMwiQGZmZmZmZiBAAAAAAAAAFkAAAAAAAAAhQJqZmZmZmSNAzczMzMzMJkDNzMzMzMwgQAAAAAAAACJAZmZmZmZmJkAzMzMzMzMmQAAAAAAAACpAZmZmZmZmJ0CamZmZmZkhQGZmZmZmZihAMzMzMzMzEUBmZmZmZmYhQDMzMzMzMyZAAAAAAAAAHkAAAAAAAAAWQAAAAAAAABhAmpmZmZmZH0DNzMzMzMweQM3MzMzMzBZAZmZmZmZmCkCamZmZmZkXQM3MzMzMzBRAMzMzMzMzGUAzMzMzMzMTQM3MzMzMzBZAzczMzMzMGEDNzMzMzMwWQDMzMzMzMxlAAAAAAAAAGkCamZmZmZkJQDMzMzMzMwtAMzMzMzMzE0BmZmZmZmYaQM3MzMzMzBpAAAAAAAAAGEBmZmZmZmYSQM3MzMzMzPw/zczMzMzM/L9mZmZmZmYOQJqZmZmZmQ1AzczMzMzMEEDNzMzMzMwMQJqZmZmZmRFAAAAAAAAAEECamZmZmZkFQM3MzMzMzBBA\",\"dtype\":\"float64\",\"shape\":[69]}}},\"id\":\"5dd9cb25-af8e-4b3b-84a8-11c8ebc3558b\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"78074b07-ae5c-4bf2-8389-4a8801e6db62\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"a113adf5-b42c-47b9-a857-4444573e8c6a\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"callback\":null},\"id\":\"3be24a8c-a908-4c98-a6d9-ea98244fbf72\",\"type\":\"DataRange1d\"},{\"attributes\":{\"items\":[{\"id\":\"ab6c671f-def2-457b-894d-f50dda24dbec\",\"type\":\"LegendItem\"},{\"id\":\"61e6c0c7-542c-4493-a2b0-fc9a123204b4\",\"type\":\"LegendItem\"}],\"plot\":{\"id\":\"84dfeaca-31ec-4b2f-a470-c6fdf60ce324\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"af36d4e6-9eae-455e-abff-4e2ec399fa35\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"dd3f3f14-5d07-4bce-947a-214f36a8e293\",\"type\":\"LinearScale\"},{\"attributes\":{\"plot\":{\"id\":\"84dfeaca-31ec-4b2f-a470-c6fdf60ce324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"ec413fca-cea1-4791-995c-8aef33ab58a1\",\"type\":\"BasicTicker\"}},\"id\":\"6ed7da78-41b4-403f-b697-b239e9538909\",\"type\":\"Grid\"},{\"attributes\":{\"below\":[{\"id\":\"3b5f9b62-a054-4527-be33-5e01c67ce396\",\"type\":\"LinearAxis\"}],\"left\":[{\"id\":\"c24fb7c3-501f-43d6-9ad9-299cde854155\",\"type\":\"LinearAxis\"}],\"renderers\":[{\"id\":\"3b5f9b62-a054-4527-be33-5e01c67ce396\",\"type\":\"LinearAxis\"},{\"id\":\"6ed7da78-41b4-403f-b697-b239e9538909\",\"type\":\"Grid\"},{\"id\":\"c24fb7c3-501f-43d6-9ad9-299cde854155\",\"type\":\"LinearAxis\"},{\"id\":\"9e2756bb-f173-4571-87af-6dcd7bf767e4\",\"type\":\"Grid\"},{\"id\":\"2522be3d-d7c4-445b-a9c0-521f48f7e0ad\",\"type\":\"BoxAnnotation\"},{\"id\":\"af36d4e6-9eae-455e-abff-4e2ec399fa35\",\"type\":\"Legend\"},{\"id\":\"249fd97e-24ae-4267-9e1c-8b81038a2a3b\",\"type\":\"GlyphRenderer\"},{\"id\":\"4318eae0-2252-4e4a-a47c-2aed93505864\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"9c7d274a-c341-46f2-8098-e6514a399193\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"52faf946-4d3e-4d45-8151-3bc1b50bfa73\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"3be24a8c-a908-4c98-a6d9-ea98244fbf72\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"dd3f3f14-5d07-4bce-947a-214f36a8e293\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"a8645f74-2dbe-4614-aa50-5749c5c388be\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"78074b07-ae5c-4bf2-8389-4a8801e6db62\",\"type\":\"LinearScale\"}},\"id\":\"84dfeaca-31ec-4b2f-a470-c6fdf60ce324\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"line_width\":{\"value\":4},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"de6164a1-b071-42af-ad5e-edf9697af198\",\"type\":\"Line\"},{\"attributes\":{\"line_color\":{\"value\":\"firebrick\"},\"line_width\":{\"value\":4},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"3e32f35e-9dc1-4428-9075-8b5aad805e9f\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"db2169bb-ea55-4bfe-8986-1352f4b8d9a6\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"154d8cac-1dc1-42da-9a7b-9fa2f98287f9\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"f94e312a-95d5-4aff-a86a-098ba4d454dd\",\"type\":\"BasicTicker\"},{\"attributes\":{\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"line_width\":{\"value\":4},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"ca19e3dd-c7d7-49dd-86e1-3219c7ba86a2\",\"type\":\"Line\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"plot\":null,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2522be3d-d7c4-445b-a9c0-521f48f7e0ad\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"callback\":null},\"id\":\"a8645f74-2dbe-4614-aa50-5749c5c388be\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"23a26ef1-d23d-4a12-93f9-23c023de227b\",\"type\":\"HelpTool\"}],\"root_ids\":[\"84dfeaca-31ec-4b2f-a470-c6fdf60ce324\"]},\"title\":\"Bokeh Application\",\"version\":\"0.12.10\"}};\n",
" var render_items = [{\"docid\":\"b8952c76-e3a2-4450-a039-0b855eedb82d\",\"elementid\":\"c829a729-7d5f-4adc-b607-5425784d1fbc\",\"modelid\":\"84dfeaca-31ec-4b2f-a470-c6fdf60ce324\"}];\n",
"\n",
" root.Bokeh.embed.embed_items(docs_json, render_items);\n",
" }\n",
"\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" } else {\n",
" var attempts = 0;\n",
" var timer = setInterval(function(root) {\n",
" if (root.Bokeh !== undefined) {\n",
" embed_document(root);\n",
" clearInterval(timer);\n",
" }\n",
" attempts++;\n",
" if (attempts > 100) {\n",
" console.log(\"Bokeh: ERROR: Unable to embed document because BokehJS library is missing\")\n",
" clearInterval(timer);\n",
" }\n",
" }, 10, root)\n",
" }\n",
"})(window);"
],
"application/vnd.bokehjs_exec.v0+json": ""
},
"metadata": {
"application/vnd.bokehjs_exec.v0+json": {
"id": "84dfeaca-31ec-4b2f-a470-c6fdf60ce324"
}
},
"output_type": "display_data"
}
],
"source": [
"# Fill up the parameters in the following function:\n",
"make_dashboard(x=x, gdp_change=gdp_change, unemployment=unemployment, title=title, file_name=file_name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"Section_5\">Question 5: Save the dashboard on IBM cloud and display it</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"From the tutorial <i>PROVISIONING AN OBJECT STORAGE INSTANCE ON IBM CLOUD</i> copy the JSON object containing the credentials you created. You’ll want to store everything you see in a credentials variable like the one below (obviously, replace the placeholder values with your own). Take special note of your <code>access_key_id</code> and <code>secret_access_key</code>. <b>Do not delete <code># @hidden_cell </code> as this will not allow people to see your credentials when you share your notebook. </b>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<code>\n",
"credentials = {<br>\n",
" &nbsp; \"apikey\": \"your-api-key\",<br>\n",
" &nbsp; \"cos_hmac_keys\": {<br>\n",
" &nbsp; \"access_key_id\": \"your-access-key-here\", <br>\n",
" &nbsp; \"secret_access_key\": \"your-secret-access-key-here\"<br>\n",
" &nbsp; },<br>\n",
"</code>\n",
"<code>\n",
" &nbsp;\"endpoints\": \"your-endpoints\",<br>\n",
" &nbsp; \"iam_apikey_description\": \"your-iam_apikey_description\",<br>\n",
" &nbsp; \"iam_apikey_name\": \"your-iam_apikey_name\",<br>\n",
" &nbsp; \"iam_role_crn\": \"your-iam_apikey_name\",<br>\n",
" &nbsp; \"iam_serviceid_crn\": \"your-iam_serviceid_crn\",<br>\n",
" &nbsp;\"resource_instance_id\": \"your-resource_instance_id\"<br>\n",
"}\n",
"</code>"
]
},
{
"cell_type": "code",
"execution_count": 123,
"metadata": {},
"outputs": [],
"source": [
"#@hidden_cell\n",
" \n",
"credentials = {\n",
" \"apikey\": \"rMZXDj45IfijMN7F5joI5FkQuRYsVyK3gO4Ej_84gro0\",\n",
" \"cos_hmac_keys\": {\n",
" \"access_key_id\": \"2b54533ca7c2405a9f23ef2bb458d7cd\",\n",
" \"secret_access_key\": \"798c215e558b2f48057ebc824c38c2f2cb88fe37f0843ebf\"\n",
" },\n",
" \"endpoints\": \"https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints\",\n",
" \"iam_apikey_description\": \"Auto-generated for key 2b54533c-a7c2-405a-9f23-ef2bb458d7cd\",\n",
" \"iam_apikey_name\": \"Dashboardgue\",\n",
" \"iam_role_crn\": \"crn:v1:bluemix:public:iam::::serviceRole:Writer\",\n",
" \"iam_serviceid_crn\": \"crn:v1:bluemix:public:iam-identity::a/4469d92ed6a7453cb2021f7aaafcdf23::serviceid:ServiceId-f214fed6-6a9d-4404-b21f-6de6ce9ca169\",\n",
" \"resource_instance_id\": \"crn:v1:bluemix:public:cloud-object-storage:global:a/4469d92ed6a7453cb2021f7aaafcdf23:74d497ee-902f-4fdb-ba49-325136d974a3::\"\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You will need the endpoint make sure the setting are the same as <i> PROVISIONING AN OBJECT STORAGE INSTANCE ON IBM CLOUD </i> assign the name of your bucket to the variable <code>bucket_name </code> "
]
},
{
"cell_type": "code",
"execution_count": 124,
"metadata": {},
"outputs": [],
"source": [
"endpoint = 'https://s3.ap-geo.objectstorage.softlayer.net'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"From the tutorial <i> PROVISIONING AN OBJECT STORAGE INSTANCE ON IBM CLOUD </i> assign the name of your bucket to the variable <code>bucket_name </code> "
]
},
{
"cell_type": "code",
"execution_count": 125,
"metadata": {},
"outputs": [],
"source": [
"bucket_name = 'teguh31' # Type your bucket name on IBM Cloud"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can access IBM Cloud Object Storage with Python useing the <code>boto3</code> library, which we’ll import below:"
]
},
{
"cell_type": "code",
"execution_count": 126,
"metadata": {},
"outputs": [],
"source": [
"import boto3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can interact with IBM Cloud Object Storage through a <code>boto3</code> resource object."
]
},
{
"cell_type": "code",
"execution_count": 127,
"metadata": {},
"outputs": [],
"source": [
"resource = boto3.resource(\n",
" 's3',\n",
" aws_access_key_id = credentials[\"cos_hmac_keys\"]['access_key_id'],\n",
" aws_secret_access_key = credentials[\"cos_hmac_keys\"][\"secret_access_key\"],\n",
" endpoint_url = endpoint,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We are going to use <code>open</code> to create a file object. To get the path of the file, you are going to concatenate the name of the file stored in the variable <code>file_name</code>. The directory stored in the variable directory using the <code>+</code> operator and assign it to the variable \n",
"<code>html_path</code>. We will use the function <code>getcwd()</code> to find current the working directory."
]
},
{
"cell_type": "code",
"execution_count": 128,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"directory = os.getcwd()\n",
"html_path = directory + \"/\" + file_name"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now you must read the html file, use the function <code>f = open(html_path, mode)</code> to create a file object and assign it to the variable <code>f</code>. The parameter <code>file</code> should be the variable <code>html_path</code>, the mode should be <code>\"r\"</code> for read. "
]
},
{
"cell_type": "code",
"execution_count": 129,
"metadata": {},
"outputs": [],
"source": [
"# Type your code here\n",
"f = open(html_path, \"r\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To load your dataset into the bucket we will use the method <code>put_object</code>, you must set the parameter name to the name of the bucket, the parameter <code>Key</code> should be the name of the HTML file and the value for the parameter Body should be set to <code>f.read()</code>."
]
},
{
"cell_type": "code",
"execution_count": 130,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"s3.Object(bucket_name='teguh31', key='index.html')"
]
},
"execution_count": 130,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Fill up the parameters in the following function:\n",
"resource.Bucket(name=bucket_name).put_object(Key=file_name, Body=f.read())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the dictionary <code>Params</code> provide the bucket name as the value for the key <i>'Bucket'</i>. Also for the value of the key <i>'Key'</i> add the name of the <code>html</code> file, both values should be strings."
]
},
{
"cell_type": "code",
"execution_count": 131,
"metadata": {},
"outputs": [],
"source": [
"# Fill in the value for each key\n",
"Params = {'Bucket':'bucket_name' ,'Key': 'file_name' }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following lines of code will generate a URL to share your dashboard. The URL only last seven days, but don't worry you will get full marks if the URL is visible in your notebook. "
]
},
{
"cell_type": "code",
"execution_count": 132,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://s3.ap-geo.objectstorage.softlayer.net/bucket_name/file_name?Signature=fKf3BJVXx3in4ZZlKoID7aNLcxo%3D&Expires=1556774117&AWSAccessKeyId=2b54533ca7c2405a9f23ef2bb458d7cd\n"
]
}
],
"source": [
"import sys\n",
"time = 7*24*60**2\n",
"client = boto3.client(\n",
" 's3',\n",
" aws_access_key_id = credentials[\"cos_hmac_keys\"]['access_key_id'],\n",
" aws_secret_access_key = credentials[\"cos_hmac_keys\"][\"secret_access_key\"],\n",
" endpoint_url=endpoint,\n",
"\n",
")\n",
"url = client.generate_presigned_url('get_object',Params=Params,ExpiresIn=time)\n",
"print(url)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"Section_5\"> How to submit </h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<p>Once you complete your notebook you will have to share it to be marked. Select the icon on the top right a marked in red in the image below, a dialogue box should open, select the option all&nbsp;content excluding sensitive code cells.</p>\n",
"\n",
"<p><img height=\"440\" width=\"700\" src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/EdX/ReadMe%20files/share_noteook1.png\" alt=\"share notebook\" /></p>\n",
"<p></p>\n",
"\n",
"<p>You can then share the notebook&nbsp; via a&nbsp; URL by scrolling down as shown in the following image:</p>\n",
"<p style=\"text-align: center;\"> <img height=\"308\" width=\"350\" src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/EdX/ReadMe%20files/link2.png\" alt=\"share notebook\" /> </p>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<p>Copyright &copy; 2019 IBM Developer Skills Network. This notebook and its source code are released under the terms of the <a href=\"https://cognitiveclass.ai/mit-license/\">MIT License</a>.</p>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>About the Authors:</h2> \n",
"\n",
"<a href=\"https://www.linkedin.com/in/joseph-s-50398b136/\">Joseph Santarcangelo</a> has a PhD in Electrical Engineering, his research focused on using machine learning, signal processing, and computer vision to determine how videos impact human cognition. Joseph has been working for IBM since he completed his PhD.\n",
"<p>\n",
"Other contributors: <a href=\"https://www.linkedin.com/in/yi-leng-yao-84451275/\">Yi leng Yao</a>, <a href=\"www.linkedin.com/in/jiahui-mavis-zhou-a4537814a\">Mavis Zhou</a> \n",
"</p>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>References :</h2> "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<ul>\n",
" <il>\n",
" 1) <a href=\"https://research.stlouisfed.org/\">Economic Research at the St. Louis Fed </a>:<a href=\"https://fred.stlouisfed.org/series/UNRATE/\"> Civilian Unemployment Rate</a>\n",
" </il> \n",
" <p>\n",
" <il>\n",
" 2) <a href=\"https://github.com/datasets\">Data Packaged Core Datasets\n",
" </a>\n",
" </il> \n",
" </p>\n",
" \n",
"</ul>\n",
"</div>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment