From 1207fe194f647c23c07198c4fc214ed1996dd3a2 Mon Sep 17 00:00:00 2001 From: Christos Botsikas Date: Tue, 25 Jun 2019 08:19:17 +0200 Subject: [PATCH] Enable Open with Visualizer Notebook updated to https://github.com/aegisbigdata/visualizer/commit/6077bb3ed6c83964ffec79b16d97085b66f72675 closes https://github.com/aegisbigdata/documentation/issues/103 https://github.com/aegisbigdata/documentation/issues/195 --- .../app/scripts/services/AegisToolsService.js | 3 +- .../main/resources/notebooks/Visualizer.ipynb | 52 +++++++++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/aegis-web/yo/app/scripts/services/AegisToolsService.js b/aegis-web/yo/app/scripts/services/AegisToolsService.js index af74eb7e4..566d6f2db 100644 --- a/aegis-web/yo/app/scripts/services/AegisToolsService.js +++ b/aegis-web/yo/app/scripts/services/AegisToolsService.js @@ -20,7 +20,8 @@ angular.module('hopsWorksApp') img: "images/tools-visualizer.png", description: "Easily transform heaps of data to a wide sset of visualisations.", documentationUrl: "https://github.com/aegisbigdata/documentation/wiki/Visualizer", - sourceUrl: "https://github.com/aegisbigdata/visualizer" + sourceUrl: "https://github.com/aegisbigdata/visualizer", + supportDatasetParam: true }, { name: "Algorithm Execution Container", diff --git a/hopsworks-common/src/main/resources/notebooks/Visualizer.ipynb b/hopsworks-common/src/main/resources/notebooks/Visualizer.ipynb index a1cccbca3..edca46258 100644 --- a/hopsworks-common/src/main/resources/notebooks/Visualizer.ipynb +++ b/hopsworks-common/src/main/resources/notebooks/Visualizer.ipynb @@ -1,5 +1,19 @@ { "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "hideCode": true + }, + "outputs": [], + "source": [ + "%%javascript\n", + "var url = new URL(window.location);\n", + "IPython.notebook.kernel.execute(\"%%local url_dataset = '\" + url.searchParams.get(\"dataset\") + \"'\")\n", + "Jupyter.notebook.execute_cells([1])" + ] + }, { "cell_type": "code", "execution_count": null, @@ -38,6 +52,14 @@ "fs = hdfs.hdfs(user='{}__{}'.format(project_name, project_user))\n", "lfs = hdfs.hdfs(\"\", 0)\n", "\n", + "# Check if visualizer was opened upon right click or not\n", + "if url_dataset == 'null':\n", + " url_dataset = None\n", + "else:\n", + " hdfs_current_dir = '/Projects/{}'.format(project_name) + '/' + url_dataset[0:url_dataset.rfind('/')]\n", + " url_dataset = url_dataset[url_dataset.rfind('/') + 1:]\n", + "\n", + "\n", "def get_directory_contents():\n", " try:\n", " contents = []\n", @@ -60,11 +82,11 @@ " contents = file_or_directory.split('---')\n", "\n", " if contents[1].strip() == 'directory':\n", - " display(Javascript(\"Jupyter.notebook.execute_cells([1])\"))\n", + " display(Javascript(\"Jupyter.notebook.execute_cells([2])\"))\n", " hdfs_current_dir = hdfs_current_dir + '/' + contents[0].strip()\n", " elif contents[1].strip() == 'file':\n", " hdfs_file_to_read = hdfs_current_dir + '/' + contents[0].strip()\n", - " display(Javascript(\"Jupyter.notebook.execute_cells([2, 3])\"))\n", + " display(Javascript(\"Jupyter.notebook.execute_cells([3, 4])\"))\n", " except:\n", " print(colored(\"An exception occured while trying to list contents.\\nPlease make sure that you have set up correctly the username and project name.\", \"red\", attrs=['bold']))\n", "\n", @@ -76,7 +98,7 @@ "def back_to_top(b):\n", " global hdfs_current_dir, hdfs_root_dir\n", " hdfs_current_dir = hdfs_root_dir\n", - " display(Javascript(\"Jupyter.notebook.execute_cells([1])\"))\n", + " display(Javascript(\"Jupyter.notebook.execute_cells([2])\"))\n", " \n", "def parameters_button_clicked(b):\n", " cell = dashboard_picker.value\n", @@ -561,7 +583,7 @@ " except:\n", " return False\n", "\n", - "Javascript(\"Jupyter.notebook.execute_cells([1])\")" + "Javascript(\"Jupyter.notebook.execute_cells([2])\")" ] }, { @@ -581,6 +603,9 @@ " current_directory = widgets.HTML(value = '

Current Directory: {}

'.format(hdfs_current_dir))\n", " dropdown = widgets.Dropdown(options=dirs, value=None, description='Folder/File:', style={'description_width': 'initial'})\n", "\n", + " if url_dataset is not None:\n", + " dropdown.value = url_dataset + ' --- file'\n", + " \n", " delimiter_dropdown = widgets.Dropdown(options=[',', ';', 'TAB'], value=',', description='CSV Delimiter:', style={'description_width': 'initial'})\n", "\n", " encoding_dropdown = widgets.Dropdown(options=['ascii', 'utf_8', 'utf_8_sig', '1252'], value='utf_8', description='Encoding', style={'description_width': 'initial'})\n", @@ -630,11 +655,7 @@ " \n", " for (var i = 0; i < ids.length; i++) {\n", " if (element.id == ids[i]) {\n", - " //IPython.notebook.kernel.execute(\"visualization_type='\" + ids[i] + \"'\");\n", - " var nb = Jupyter.notebook;\n", - " var cell = nb.get_cell(4);\n", - " cell.set_text(\"%%local\\nvisualization_type='\" + ids[i] + \"'\");\n", - " cell.execute();\n", + " IPython.notebook.kernel.execute(\"%%local visualization_type='\" + ids[i] + \"'\");\n", " } else {\n", " $(\"#\" + ids[i]).prop(\"checked\", false);\n", " }\n", @@ -770,19 +791,6 @@ "" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "hideCode": true, - "hidePrompt": false - }, - "outputs": [], - "source": [ - "%%local\n", - "visualization_type='choropleth'" - ] - }, { "cell_type": "code", "execution_count": null,