Skip to content

Commit

Permalink
Enable Open with Visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
cbotsikas committed Jun 25, 2019
1 parent b8d60f5 commit 1207fe1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
3 changes: 2 additions & 1 deletion aegis-web/yo/app/scripts/services/AegisToolsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 30 additions & 22 deletions hopsworks-common/src/main/resources/notebooks/Visualizer.ipynb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -561,7 +583,7 @@
" except:\n",
" return False\n",
"\n",
"Javascript(\"Jupyter.notebook.execute_cells([1])\")"
"Javascript(\"Jupyter.notebook.execute_cells([2])\")"
]
},
{
Expand All @@ -581,6 +603,9 @@
" current_directory = widgets.HTML(value = '<h4>Current Directory: <b>{}</b></h4>'.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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -770,19 +791,6 @@
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hideCode": true,
"hidePrompt": false
},
"outputs": [],
"source": [
"%%local\n",
"visualization_type='choropleth'"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 1207fe1

Please sign in to comment.