{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions.\n",
"\n",
"Install the mechanize gem version ~>2.7.5 for using mechanize functions.\n"
]
},
{
"data": {
"application/javascript": [
"if(window['d3'] === undefined ||\n",
" window['Nyaplot'] === undefined){\n",
" var path = {\"d3\":\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\",\"downloadable\":\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\"};\n",
"\n",
"\n",
"\n",
" var shim = {\"d3\":{\"exports\":\"d3\"},\"downloadable\":{\"exports\":\"downloadable\"}};\n",
"\n",
" require.config({paths: path, shim:shim});\n",
"\n",
"\n",
"require(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\n",
"\n",
"\tvar script = d3.select(\"head\")\n",
"\t .append(\"script\")\n",
"\t .attr(\"src\", \"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\")\n",
"\t .attr(\"async\", true);\n",
"\n",
"\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\n",
"\n",
"\n",
"\t var event = document.createEvent(\"HTMLEvents\");\n",
"\t event.initEvent(\"load_nyaplot\",false,false);\n",
"\t window.dispatchEvent(event);\n",
"\t console.log('Finished loading Nyaplotjs');\n",
"\n",
"\t};\n",
"\n",
"\n",
"});});\n",
"}\n"
],
"text/plain": [
"\"if(window['d3'] === undefined ||\\n window['Nyaplot'] === undefined){\\n var path = {\\\"d3\\\":\\\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\\\",\\\"downloadable\\\":\\\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\\\"};\\n\\n\\n\\n var shim = {\\\"d3\\\":{\\\"exports\\\":\\\"d3\\\"},\\\"downloadable\\\":{\\\"exports\\\":\\\"downloadable\\\"}};\\n\\n require.config({paths: path, shim:shim});\\n\\n\\nrequire(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\\n\\n\\tvar script = d3.select(\\\"head\\\")\\n\\t .append(\\\"script\\\")\\n\\t .attr(\\\"src\\\", \\\"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\\\")\\n\\t .attr(\\\"async\\\", true);\\n\\n\\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\\n\\n\\n\\t var event = document.createEvent(\\\"HTMLEvents\\\");\\n\\t event.initEvent(\\\"load_nyaplot\\\",false,false);\\n\\t window.dispatchEvent(event);\\n\\t console.log('Finished loading Nyaplotjs');\\n\\n\\t};\\n\\n\\n});});\\n}\\n\""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"require 'daru/view'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
":datatables"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Daru::View.table_library = :datatables"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" Daru::DataFrame(5x3) \n",
"
\n",
" \n",
" \n",
" \n",
" | \n",
" \n",
" a | \n",
" \n",
" b | \n",
" \n",
" c | \n",
" \n",
"
\n",
" \n",
"\n",
" \n",
" \n",
" \n",
" one | \n",
" \n",
" 1 | \n",
" \n",
" 11 | \n",
" \n",
" 11 | \n",
" \n",
"
\n",
" \n",
" \n",
" two | \n",
" \n",
" 2 | \n",
" \n",
" 12 | \n",
" \n",
" 22 | \n",
" \n",
"
\n",
" \n",
" \n",
" three | \n",
" \n",
" 3 | \n",
" \n",
" 13 | \n",
" \n",
" 33 | \n",
" \n",
"
\n",
" \n",
" \n",
" four | \n",
" \n",
" 4 | \n",
" \n",
" 14 | \n",
" \n",
" 44 | \n",
" \n",
"
\n",
" \n",
" \n",
" five | \n",
" \n",
" 5 | \n",
" \n",
" 15 | \n",
" \n",
" 55 | \n",
" \n",
"
\n",
" \n",
"\n",
" \n",
"\n",
"
"
],
"text/plain": [
"#\n",
" a b c\n",
" one 1 11 11\n",
" two 2 12 22\n",
" three 3 13 33\n",
" four 4 14 44\n",
" five 5 15 55"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = Daru::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],\n",
" c: [11,22,33,44,55]},\n",
" order: [:a, :b, :c],\n",
" index: [:one, :two, :three, :four, :five])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"#\n",
" a b c\n",
" one 1 11 11\n",
" two 2 12 22\n",
" three 3 13 33\n",
" four 4 14 44\n",
" five 5 15 55, @options={:pageLength=>3}, @adapter=Daru::View::Adapter::DatatablesAdapter, @table=#3}>>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dt_df = Daru::View::Table.new(df, pageLength: 3)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"\\n\\n\""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dt_df.table.to_html"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"\\n\\n\\n \\n \\n Num1 | \\n Num2 | \\n Num3 | \\n
\\n
\""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
" table_opts = {\n",
" class: \"display\",\n",
" cellspacing: \"0\",\n",
" width: \"50%\",\n",
" table_html: \"\n",
" \n",
" \n",
" Num1 | \n",
" Num2 | \n",
" Num3 | \n",
"
\n",
" \"\n",
" }\n",
" options = {\n",
" table_options: table_opts\n",
" }\n",
"html_code_dt_df = dt_df.table.to_html(id='table_id4', options)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" \n",
" Num1 | \n",
" Num2 | \n",
" Num3 | \n",
"
\n",
"
"
],
"text/plain": [
"\"\\n\\n\\n \\n \\n Num1 | \\n Num2 | \\n Num3 | \\n
\\n
\""
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"IRuby.html html_code_dt_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Ruby 2.4.1",
"language": "ruby",
"name": "ruby"
},
"language_info": {
"file_extension": ".rb",
"mimetype": "application/x-ruby",
"name": "ruby",
"version": "2.4.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}