{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Note\n", "\n", "Please visit https://github.com/Shekharrajak/daru-data_tables for updated API and examples. It works in Ruby web application framework but there is already an issue open for IRuby notebook: https://github.com/Shekharrajak/daru-data_tables/issues/2\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/shekharrajak/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/bundler/gems/daru-data_tables-af3460a049da/lib/daru/data_tables/version.rb:3: warning: already initialized constant Daru::View::VERSION\n", "/home/shekharrajak/Documents/githubRepos/sciruby/windows-daru-view/daru-view/lib/daru/view/version.rb:3: warning: previous definition of VERSION was here\n" ] }, { "data": { "text/plain": [ "true" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "require 'daru/data_tables'\n", "require 'daru'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(5x3) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
abc
one11111
two21222
three31333
four41444
five51555
" ], "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": 2, "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": 3, "metadata": {}, "outputs": [], "source": [ "# Please refer: https://github.com/Shekharrajak/daru-data_tables/issues/2\n", "# Daru::View::DataTables.init_iruby\n", "# t = DataTables::DataTable.new(pageLength: 3)\n", "# t.to_html\n", "# t.to_html(id='table_id1')\n", "# table_opts = {\n", "# class: \"display\", \n", "# cellspacing: \"0\",\n", "# width: \"100%\" \n", "# }\n", "# options ={\n", "# table_options: table_opts\n", "# } \n", "# t.to_html(id='table_id1', options)\n", "\n", "# id is automatically added into table_options\n", "# options\n", "# options[:table_options][:table_html] = df.to_html_thead + df.to_html_tbody\n", "# html_code = t.to_html(id='table_id1', options)\n", "# Fix me: It is showing normal html code. That means DataTables js and css is not working or loading.\n", "# IRuby.html html_code\n", "# html_code.html_safe\n", "# Fix me: It is showing normal html code. That means DataTables js and css is not working or loading.\n", "# IRuby.html html_code\n", "\n", "# t_opts = {\n", "# data: [[1,1,1],\n", "# [1,2,3],\n", "# [11,12,13],\n", "# [1,2,3],\n", "# [11,12,13],\n", "# [1,2,3],\n", "# [11,12,13]\n", "# ],\n", "# pageLength: 4\n", "# }\n", "# table_from_array = DataTables::DataTable.new(t_opts)\n", "# 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_array_sorted = table_from_array.to_html(id='table_id4', options)\n", "\n", "# IRuby.html html_code_array_sorted\n", "\n", "# IRuby.display(IRuby.javascript(table_from_array.to_html('id1')))\n", "# IRuby.html(table_from_array.to_html(id='table_id4', options))\n", "# table_html = \"\n", "# \n", "# \n", "# \n", "# \n", "# \n", "# \n", "# \n", "# \n", "#
Num1 Num2 Num3
\"\n", "# IRuby.html table_html\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.5.3", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.5.3" } }, "nbformat": 4, "nbformat_minor": 2 }