{"payload":{"allShortcutsEnabled":false,"fileTree":{"work":{"items":[{"name":"01_simple_script.py","path":"work/01_simple_script.py","contentType":"file"},{"name":"02_bakery_dataframes.py","path":"work/02_bakery_dataframes.py","contentType":"file"},{"name":"03_load_sql.py","path":"work/03_load_sql.py","contentType":"file"},{"name":"04_pyspark_demo_notebook.ipynb","path":"work/04_pyspark_demo_notebook.ipynb","contentType":"file"},{"name":"05_pyspark_demo_notebook.ipynb","path":"work/05_pyspark_demo_notebook.ipynb","contentType":"file"},{"name":"05_pyspark_demo_notebook_emr.ipynb","path":"work/05_pyspark_demo_notebook_emr.ipynb","contentType":"file"},{"name":"BreadBasket_DMS.csv","path":"work/BreadBasket_DMS.csv","contentType":"file"},{"name":"bakery_sample.sql","path":"work/bakery_sample.sql","contentType":"file"},{"name":"emr_cli_command.sh","path":"work/emr_cli_command.sh","contentType":"file"},{"name":"install-my-jupyter-libraries.sh","path":"work/install-my-jupyter-libraries.sh","contentType":"file"},{"name":"postgresql-42.2.10.jar","path":"work/postgresql-42.2.10.jar","contentType":"file"}],"totalCount":11},"":{"items":[{"name":"work","path":"work","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"requirements.txt","path":"requirements.txt","contentType":"file"},{"name":"stack.yml","path":"stack.yml","contentType":"file"}],"totalCount":6}},"fileTreeProcessingTime":10.459672999999999,"foldersToFetch":[],"repo":{"id":157301816,"defaultBranch":"v2","name":"pyspark-setup-demo","ownerLogin":"garystafford","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2018-11-13T01:29:48.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/1365830?v=4","public":true,"private":false,"isOrgOwned":false},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1575384389.0","canEdit":false,"refType":"branch","currentOid":"f9d0a99f3cf865ddc347a31529d4ea1daa96973f"},"path":"work/04_pyspark_demo_notebook.ipynb","currentUser":null,"blob":{"rawLines":["{"," \"cells\": ["," {"," \"cell_type\": \"markdown\","," \"metadata\": {},"," \"source\": ["," \"# PySpark Demo Notebook\\n\","," \"## Demo\\n\","," \"1. Run PostgreSQL Script\\n\","," \"2. Load PostgreSQL Data\\n\","," \"3. Create New Record\\n\","," \"4. Write New Record to PostgreSQL Table\\n\","," \"5. Load CSV Data File\\n\","," \"6. Write Data to PostgreSQL\\n\","," \"7. Analyze Data with Spark SQL\\n\","," \"8. Graph Data with BokehJS\\n\","," \"9. Read and Write Data to Parquet Format\\n\","," \"\\n\","," \"_Prepared by: [Gary A. Stafford](https://twitter.com/GaryStafford) \\n\","," \"Associated article: https://wp.me/p1RD28-61V_\""," ]"," },"," {"," \"cell_type\": \"markdown\","," \"metadata\": {},"," \"source\": ["," \"### Run PostgreSQL Script\\n\","," \"Run the PostgreSQL sql script\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 1,"," \"metadata\": {"," \"pycharm\": {"," \"is_executing\": false"," }"," },"," \"outputs\": [],"," \"source\": ["," \"! pip install psycopg2-binary --upgrade --quiet\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 2,"," \"metadata\": {"," \"pycharm\": {"," \"is_executing\": false"," }"," },"," \"outputs\": ["," {"," \"name\": \"stdout\","," \"output_type\": \"stream\","," \"text\": ["," \"DROP TABLE IF EXISTS \\\"bakery_basket\\\"\\n\","," \"\\n\","," \"DROP SEQUENCE IF EXISTS bakery_basket_id_seq\\n\","," \"\\n\","," \"CREATE SEQUENCE bakery_basket_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1\\n\","," \"\\n\","," \"\\n\","," \"CREATE TABLE \\\"public\\\".\\\"bakery_basket\\\"\\n\","," \"(\\n\","," \" \\\"id\\\" integer DEFAULT nextval('bakery_basket_id_seq') NOT NULL,\\n\","," \" \\\"date\\\" character varying(10) NOT NULL,\\n\","," \" \\\"time\\\" character varying(8) NOT NULL,\\n\","," \" \\\"transaction\\\" integer NOT NULL,\\n\","," \" \\\"item\\\" character varying(50) NOT NULL\\n\","," \") WITH (oids = false)\\n\","," \"\\n\","," \"\\n\","," \"INSERT INTO \\\"bakery_basket\\\" (\\\"date\\\", \\\"time\\\", \\\"transaction\\\", \\\"item\\\", \\\"id\\\")\\n\","," \"VALUES ('2016-10-30', '09:58:11', 1, 'Bread', 1),\\n\","," \" ('2016-10-30', '10:05:34', 2, 'Scandinavian', 2),\\n\","," \" ('2016-10-30', '10:07:57', 3, 'Hot chocolate', 3)\\n\","," \"\\n\","," \"\\n\""," ]"," }"," ],"," \"source\": ["," \"%run -i '03_load_sql.py'\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 3,"," \"metadata\": {"," \"pycharm\": {"," \"is_executing\": false"," }"," },"," \"outputs\": [],"," \"source\": ["," \"from pyspark.sql import SparkSession\\n\","," \"from pyspark.sql.functions import to_timestamp\\n\","," \"from pyspark.sql.types import StructType, StructField, StringType, IntegerType\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 4,"," \"metadata\": {"," \"pycharm\": {"," \"is_executing\": false"," }"," },"," \"outputs\": [],"," \"source\": ["," \"spark = SparkSession \\\\\\n\","," \" .builder \\\\\\n\","," \" .appName('pyspark_demo_app') \\\\\\n\","," \" .config('spark.driver.extraClassPath',\\n\","," \" 'postgresql-42.2.10.jar') \\\\\\n\","," \" .master(\\\"local[*]\\\") \\\\\\n\","," \" .getOrCreate()\""," ]"," },"," {"," \"cell_type\": \"markdown\","," \"metadata\": {},"," \"source\": ["," \"### Load PostgreSQL Data\\n\","," \"Load the PostgreSQL 'bakery_basket' table's contents into a DataFrame\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 5,"," \"metadata\": {"," \"pycharm\": {"," \"is_executing\": false"," }"," },"," \"outputs\": [],"," \"source\": ["," \"properties = {\\n\","," \" 'driver': 'org.postgresql.Driver',\\n\","," \" 'url': 'jdbc:postgresql://postgres:5432/demo',\\n\","," \" 'user': 'postgres',\\n\","," \" 'password': 'postgres1234',\\n\","," \" 'dbtable': 'bakery_basket',\\n\","," \"}\\n\","," \"\\n\","," \"df1 = spark.read \\\\\\n\","," \" .format('jdbc') \\\\\\n\","," \" .option('driver', properties['driver']) \\\\\\n\","," \" .option('url', properties['url']) \\\\\\n\","," \" .option('user', properties['user']) \\\\\\n\","," \" .option('password', properties['password']) \\\\\\n\","," \" .option('dbtable', properties['dbtable']) \\\\\\n\","," \" .load()\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 6,"," \"metadata\": {"," \"pycharm\": {"," \"is_executing\": true"," },"," \"scrolled\": true"," },"," \"outputs\": ["," {"," \"name\": \"stdout\","," \"output_type\": \"stream\","," \"text\": ["," \"+---+----------+--------+-----------+-------------+\\n\","," \"| id| date| time|transaction| item|\\n\","," \"+---+----------+--------+-----------+-------------+\\n\","," \"| 1|2016-10-30|09:58:11| 1| Bread|\\n\","," \"| 2|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"| 3|2016-10-30|10:07:57| 3|Hot chocolate|\\n\","," \"+---+----------+--------+-----------+-------------+\\n\","," \"\\n\","," \"CPU times: user 0 ns, sys: 0 ns, total: 0 ns\\n\","," \"Wall time: 3.98 s\\n\""," ]"," }"," ],"," \"source\": ["," \"%%time\\n\","," \"df1.show(10)\\n\","," \"df1.count()\""," ]"," },"," {"," \"cell_type\": \"markdown\","," \"metadata\": {},"," \"source\": ["," \"### Create New Record\\n\","," \"Create a new bakery record and load into a DataFrame\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 7,"," \"metadata\": {"," \"pycharm\": {"," \"is_executing\": false"," }"," },"," \"outputs\": [],"," \"source\": ["," \"data = [('2016-10-30', '10:13:27', 2, 'Pastry')]\\n\","," \"\\n\","," \"bakery_schema = StructType([\\n\","," \" StructField('date', StringType(), True),\\n\","," \" StructField('time', StringType(), True),\\n\","," \" StructField('transaction', IntegerType(), True),\\n\","," \" StructField('item', StringType(), True)\\n\","," \"])\\n\","," \"\\n\","," \"df2 = spark.createDataFrame(data, bakery_schema)\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 8,"," \"metadata\": {},"," \"outputs\": ["," {"," \"name\": \"stdout\","," \"output_type\": \"stream\","," \"text\": ["," \"+----------+--------+-----------+------+\\n\","," \"| date| time|transaction| item|\\n\","," \"+----------+--------+-----------+------+\\n\","," \"|2016-10-30|10:13:27| 2|Pastry|\\n\","," \"+----------+--------+-----------+------+\\n\","," \"\\n\""," ]"," },"," {"," \"data\": {"," \"text/plain\": ["," \"1\""," ]"," },"," \"execution_count\": 8,"," \"metadata\": {},"," \"output_type\": \"execute_result\""," }"," ],"," \"source\": ["," \"df2.show()\\n\","," \"df2.count()\""," ]"," },"," {"," \"cell_type\": \"markdown\","," \"metadata\": {},"," \"source\": ["," \"### Write New Record to PostgreSQL Table\\n\","," \"Append the contents of the DataFrame to the PostgreSQL 'bakery_basket' table\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 9,"," \"metadata\": {},"," \"outputs\": [],"," \"source\": ["," \"df2.write \\\\\\n\","," \" .format('jdbc') \\\\\\n\","," \" .option('driver', properties['driver']) \\\\\\n\","," \" .option('url', properties['url']) \\\\\\n\","," \" .option('user', properties['user']) \\\\\\n\","," \" .option('password', properties['password']) \\\\\\n\","," \" .option('dbtable', properties['dbtable']) \\\\\\n\","," \" .mode('append') \\\\\\n\","," \" .save()\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 10,"," \"metadata\": {},"," \"outputs\": ["," {"," \"name\": \"stdout\","," \"output_type\": \"stream\","," \"text\": ["," \"+---+----------+--------+-----------+-------------+\\n\","," \"| id| date| time|transaction| item|\\n\","," \"+---+----------+--------+-----------+-------------+\\n\","," \"| 1|2016-10-30|09:58:11| 1| Bread|\\n\","," \"| 2|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"| 3|2016-10-30|10:07:57| 3|Hot chocolate|\\n\","," \"| 1|2016-10-30|10:13:27| 2| Pastry|\\n\","," \"+---+----------+--------+-----------+-------------+\\n\","," \"\\n\""," ]"," },"," {"," \"data\": {"," \"text/plain\": ["," \"4\""," ]"," },"," \"execution_count\": 10,"," \"metadata\": {},"," \"output_type\": \"execute_result\""," }"," ],"," \"source\": ["," \"df1.show(10)\\n\","," \"df1.count()\""," ]"," },"," {"," \"cell_type\": \"markdown\","," \"metadata\": {},"," \"source\": ["," \"### Load CSV File Data\\n\","," \"Load the Kaggle dataset from the CSV file, containing ~21K records, into a DataFrame\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 11,"," \"metadata\": {},"," \"outputs\": ["," {"," \"name\": \"stdout\","," \"output_type\": \"stream\","," \"text\": ["," \"-rw-r--r-- 1 garystafford users 694K Nov 10 2018 BreadBasket_DMS.csv\\r\\n\""," ]"," }"," ],"," \"source\": ["," \"! ls -lh *.csv\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 12,"," \"metadata\": {},"," \"outputs\": [],"," \"source\": ["," \"df3 = spark.read \\\\\\n\","," \" .format(\\\"csv\\\") \\\\\\n\","," \" .option(\\\"header\\\", \\\"true\\\") \\\\\\n\","," \" .load(\\\"BreadBasket_DMS.csv\\\", schema=bakery_schema)\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 13,"," \"metadata\": {},"," \"outputs\": ["," {"," \"name\": \"stdout\","," \"output_type\": \"stream\","," \"text\": ["," \"+----------+--------+-----------+-------------+\\n\","," \"| date| time|transaction| item|\\n\","," \"+----------+--------+-----------+-------------+\\n\","," \"|2016-10-30|09:58:11| 1| Bread|\\n\","," \"|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"|2016-10-30|10:07:57| 3|Hot chocolate|\\n\","," \"|2016-10-30|10:07:57| 3| Jam|\\n\","," \"|2016-10-30|10:07:57| 3| Cookies|\\n\","," \"|2016-10-30|10:08:41| 4| Muffin|\\n\","," \"|2016-10-30|10:13:03| 5| Coffee|\\n\","," \"|2016-10-30|10:13:03| 5| Pastry|\\n\","," \"|2016-10-30|10:13:03| 5| Bread|\\n\","," \"+----------+--------+-----------+-------------+\\n\","," \"only showing top 10 rows\\n\","," \"\\n\""," ]"," },"," {"," \"data\": {"," \"text/plain\": ["," \"21293\""," ]"," },"," \"execution_count\": 13,"," \"metadata\": {},"," \"output_type\": \"execute_result\""," }"," ],"," \"source\": ["," \"df3.show(10)\\n\","," \"df3.count()\""," ]"," },"," {"," \"cell_type\": \"markdown\","," \"metadata\": {},"," \"source\": ["," \"### Write Data to PostgreSQL\\n\","," \"Append the contents of the DataFrame to the PostgreSQL 'bakery_basket' table\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 14,"," \"metadata\": {},"," \"outputs\": [],"," \"source\": ["," \"df3.write \\\\\\n\","," \" .format('jdbc') \\\\\\n\","," \" .option('driver', properties['driver']) \\\\\\n\","," \" .option('url', properties['url']) \\\\\\n\","," \" .option('user', properties['user']) \\\\\\n\","," \" .option('password', properties['password']) \\\\\\n\","," \" .option('dbtable', properties['dbtable']) \\\\\\n\","," \" .mode('append') \\\\\\n\","," \" .save()\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 15,"," \"metadata\": {},"," \"outputs\": ["," {"," \"name\": \"stdout\","," \"output_type\": \"stream\","," \"text\": ["," \"+---+----------+--------+-----------+-------------+\\n\","," \"| id| date| time|transaction| item|\\n\","," \"+---+----------+--------+-----------+-------------+\\n\","," \"| 1|2016-10-30|09:58:11| 1| Bread|\\n\","," \"| 2|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"| 3|2016-10-30|10:07:57| 3|Hot chocolate|\\n\","," \"| 1|2016-10-30|10:13:27| 2| Pastry|\\n\","," \"| 2|2016-10-30|09:58:11| 1| Bread|\\n\","," \"| 3|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"| 4|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"| 5|2016-10-30|10:07:57| 3|Hot chocolate|\\n\","," \"| 6|2016-10-30|10:07:57| 3| Jam|\\n\","," \"| 7|2016-10-30|10:07:57| 3| Cookies|\\n\","," \"+---+----------+--------+-----------+-------------+\\n\","," \"only showing top 10 rows\\n\","," \"\\n\""," ]"," },"," {"," \"data\": {"," \"text/plain\": ["," \"21297\""," ]"," },"," \"execution_count\": 15,"," \"metadata\": {},"," \"output_type\": \"execute_result\""," }"," ],"," \"source\": ["," \"df1.show(10)\\n\","," \"df1.count()\""," ]"," },"," {"," \"cell_type\": \"markdown\","," \"metadata\": {},"," \"source\": ["," \"### Analyze Data with Spark SQL\\n\","," \"Analyze the DataFrame's bakery data using Spark SQL\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 16,"," \"metadata\": {},"," \"outputs\": ["," {"," \"name\": \"stdout\","," \"output_type\": \"stream\","," \"text\": ["," \"+---+----------+--------+-----------+-------------+\\n\","," \"| id| date| time|transaction| item|\\n\","," \"+---+----------+--------+-----------+-------------+\\n\","," \"| 1|2016-10-30|09:58:11| 1| Bread|\\n\","," \"| 2|2016-10-30|09:58:11| 1| Bread|\\n\","," \"| 2|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"| 3|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"| 4|2016-10-30|10:05:34| 2| Scandinavian|\\n\","," \"| 1|2016-10-30|10:13:27| 2| Pastry|\\n\","," \"| 3|2016-10-30|10:07:57| 3|Hot chocolate|\\n\","," \"| 6|2016-10-30|10:07:57| 3| Jam|\\n\","," \"| 5|2016-10-30|10:07:57| 3|Hot chocolate|\\n\","," \"| 7|2016-10-30|10:07:57| 3| Cookies|\\n\","," \"+---+----------+--------+-----------+-------------+\\n\","," \"only showing top 10 rows\\n\","," \"\\n\""," ]"," },"," {"," \"data\": {"," \"text/plain\": ["," \"21297\""," ]"," },"," \"execution_count\": 16,"," \"metadata\": {},"," \"output_type\": \"execute_result\""," }"," ],"," \"source\": ["," \"df1.createOrReplaceTempView(\\\"bakery_table\\\")\\n\","," \"df4 = spark.sql(\\\"SELECT * FROM bakery_table \\\" +\\n\","," \" \\\"ORDER BY transaction, date, time\\\")\\n\","," \"df4.show(10)\\n\","," \"df4.count()\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 17,"," \"metadata\": {},"," \"outputs\": ["," {"," \"name\": \"stdout\","," \"output_type\": \"stream\","," \"text\": ["," \"+----------+\\n\","," \"|item_count|\\n\","," \"+----------+\\n\","," \"| 95|\\n\","," \"+----------+\\n\","," \"\\n\","," \"+-------------+-----+\\n\","," \"| item|count|\\n\","," \"+-------------+-----+\\n\","," \"| Coffee| 5471|\\n\","," \"| Bread| 3326|\\n\","," \"| Tea| 1435|\\n\","," \"| Cake| 1025|\\n\","," \"| Pastry| 857|\\n\","," \"| Sandwich| 771|\\n\","," \"| Medialuna| 616|\\n\","," \"|Hot chocolate| 591|\\n\","," \"| Cookies| 540|\\n\","," \"| Brownie| 379|\\n\","," \"+-------------+-----+\\n\","," \"\\n\""," ]"," }"," ],"," \"source\": ["," \"df5 = spark.sql(\\\"SELECT COUNT(DISTINCT item) AS item_count FROM bakery_table\\\")\\n\","," \"df5.show()\\n\","," \"\\n\","," \"df5 = spark.sql(\\\"SELECT item, count(*) as count \\\" +\\n\","," \" \\\"FROM bakery_table \\\" +\\n\","," \" \\\"WHERE item NOT LIKE 'NONE' \\\" +\\n\","," \" \\\"GROUP BY item ORDER BY count DESC \\\" +\\n\","," \" \\\"LIMIT 10\\\")\\n\","," \"df5.show()\""," ]"," },"," {"," \"cell_type\": \"markdown\","," \"metadata\": {},"," \"source\": ["," \"### Graph Data with BokehJS\\n\","," \"Create a vertical bar chart displaying DataFrame data\""," ]"," },"," {"," \"cell_type\": \"code\","," \"execution_count\": 18,"," \"metadata\": {},"," \"outputs\": ["," {"," \"data\": {"," \"text/html\": ["," \"\\n\","," \"
\""," ]"," },"," \"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 != null && id in Bokeh.index) {\\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 id = msg.content.text.trim();\\n\","," \" if (id in Bokeh.index) {\\n\","," \" Bokeh.index[id].model.document.clear();\\n\","," \" delete Bokeh.index[id];\\n\","," \" }\\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[toinsert.length - 1].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[toinsert.length - 1].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[toinsert.length - 1]);\\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\","," \" \\\"\\\\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\","," \" \\\"
\\\\n\\\"+\\n\","," \" \\\"\\\\n\\\"+\\n\","," \" \\\"from bokeh.resources import INLINE\\\\n\\\"+\\n\","," \" \\\"output_notebook(resources=INLINE)\\\\n\\\"+\\n\","," \" \\\"
\\\\n\\\"+\\n\","," \" \\\"\\\\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 \\\"
\\\\n\\\"+\\n \\\"\\\\n\\\"+\\n \\\"from bokeh.resources import INLINE\\\\n\\\"+\\n \\\"output_notebook(resources=INLINE)\\\\n\\\"+\\n \\\"
\\\\n\\\"+\\n \\\"