PrettyTables.jl now has initial support for HTML output

Hi all, @Ronis_BR has been working with us in the Sublime Text 3: Worth a look! thread, to get a dynamic browser preview of the html output from PrettyTables.jl. We have it working, and the solution works fine without Sublime Text and just using the REPL plus the OpenSource Node app reload:

The key here is to instead of outputting the table to the REPL, to send it to a .html file. In the screenshot, there is a shell on the left side of monitor (quickly done using the Super(Win)+LeftArrow key). The shell has 2 tabs, one with the REPL running as show, and another with reload running. When you run reload -b while in the directory to which your .html file is written by PrettyTables, it launches a browser. Each time the html file is changed (due to changes in the REPL and new output), the browser automatically refreshes with the new output. The browser was placed on right side of monitor with Super(Win)+RightArrow key.


and, here’s the code if you want to run it. Be sure to use the Master branch, or the HTMLDecoration and other functionality won’t work!

## PrettyTables in REPL to Browser  - Workflow for Live-Reload
# ref: 
# The '-g' option in the npm install command installs the app globally
# $ sudo npm install -g reload                                          [1]
# /usr/bin/reload -> /usr/lib/node_modules/reload/bin/reload
# + reload@3.0.3
# added 50 packages from 53 contributors in 8.159s
# 
# pwd()
# "/home/e/Documents/eds2020_xps15/julia/workflow/html-st3"
# This is where HTML file will be saved by PrettyTables, alter as needed.
# Send the 3 line-output command to write the index.html file.
# Once file is present in directory, navigate to directory in a terminal shell.
# Enter following command to run 'reload' app and launch a browser with '-b'
# $ reload -b
#
# This is what it will look like when running, with a new line for each time index.html changes:
# ~/.../workflow/html-st3 >>> reload -b                                                                
# Reload web server:
# listening on port 8080
# monitoring dir /home/e/Documents/eds2020_xps15/julia/workflow/html-st3
# Server restarted  at 12:52:16
# Server restarted  at 12:52:48

using PrettyTables

t = 0:1:20;
data = hcat(t, ones(length(t))*1, 1*t, 0.5.*t.^2);
header = ["Time" "Acceleration" "Velocity" "Distance";
               "[s]"       "[m/s²]"    "[m/s]"      "[m]"];

hl_v = HTMLHighlighter( (data,i,j)->(j == 3) && data[i,3] > 9, HTMLDecoration(color = "blue", font_weight = "bold"));
hl_p = HTMLHighlighter( (data,i,j)->(j == 4) && data[i,4] > 10, HTMLDecoration(color = "red"));
hl_e = HTMLHighlighter( (data,i,j)->data[i,1] == 10, HTMLDecoration(background = "gray", color = "white"));

# The below line outputs to the REPL. We skip this with the HTML output
# pretty_table(data, header, backend = :html, highlighters = (hl_e, hl_p, hl_v, hl_e))
# 
# After updating any code, highlight below 3-lines and ctrl-enter to send to REPL. HTML will refresh
open("index.html", "w") do f
pretty_table(f, data, header, backend = :html, highlighters = (hl_e, hl_p, hl_v, hl_e))
end

Thanks again for your work Ronis!! :+1:

3 Likes