{ "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": { "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", " \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": 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, :data=>[[0, 1, 11, 11], [1, 2, 12, 22], [2, 3, 13, 33], [3, 4, 14, 44], [4, 5, 15, 55]]}, @user_options={}, @adapter=Daru::View::Adapter::DatatablesAdapter, @table=#{:class=>\"display\", :cellspacing=>\"0\", :width=>\"100%\"}}, @data=#\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, :data=>[[0, 1, 11, 11], [1, 2, 12, 22], [2, 3, 13, 33], [3, 4, 14, 44], [4, 5, 15, 55]]}>>" ] }, "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/html": [ "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
abc
" ], "text/plain": [ "\"\\n\\n\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n
abc
\"" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dt_df.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"\\n\\n\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n
abc
\"" ] }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
abc
" ], "text/plain": [ "\"\\n\\n\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n
abc
\"" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IRuby.html html_code_dt_df" ] }, { "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 }