Is there a way to compile interactive tables into an HTML book in Julia?

My lab uses HTML notebooks to communicate information to stakeholders.

I am curious about migrating my workflow from R to Julia but am having trouble replicating an interactive table that I can include in the book like DT + bookdown in R or itables + jupyter-book in Python.

I’ve tried using ipynbs and making an R or Python call via RCall or PyCall just for the corresponding table function I need but the table isn’t displayed (I am assuming there a is a type issue here). What I tried:

PyCall


py"""

# example from the docs
import itables 
import pandas as pd
import numpy as np

df = pd.DataFrame({
    'cups_of_coffee': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
    'productivity': [2, 5, 6, 8, 9, 8, 0, 1, 0, -1]
})

itables.show(df)

"""py

This was probably a naive experiment and doesn’t return or display anything in the book.

RCall

using RCall

R"

library(DT)
x <- datatable(mtcars)
"
# this gives me an ordered dict of the dataset (fair enough!)
@rget x

TableView.jl

I’ve also tried TableView.jl which works great when I’m using the live Jupyter Lab interface…

using RDatasets
using TableView

# great!
mtcars = dataset("datasets", "mtcars");

…but doesn’t appear in the finished book when I compile to jupyter-book. It gives an error about not detecting the required extension in the environment (again, only when building the book):

WebIO not detected.

Please read the troubleshooting guide for more information on how to resolve this issue.

https://juliagizmos.github.io/WebIO.jl/latest/troubleshooting/not-detected/

This suggests perhaps I could resolve the issue by including the extension in the compilation environment somehow, but before I spent a bunch more time on it I wanted to make sure I hadn’t overlooked an existing solution.

Are there solutions I’m missing, and, if not, what are some steps I might try to get an interactive table compiled into an HTML book?

EDIT: typo and…
NOTE: the issue with TableView.jl happens when I use jupyter-book and weave.jl, so I am guessing it’s just not designed with this in mind.

Maybe Books.jl might be what you are looking for? https://github.com/JuliaBooks/Books.jl

@rikh would certainly know more about it than I.

2 Likes

Thank you! This looks like the right idea, I’ll give it a test!

Interactive tables are not in Books.jl and I also suspect that you’re more into single page conversions which is not a focus of Books.jl

PlutoSliderServer has some more dynamic capabilities. Or what does an “interactive table” mean? Is it an HTML table with a bunch of Javascript on top (static) or does it also require a server?

1 Like

Thanks!

In terms of what I need to be able to replicate to leave R, it would be a table my end users can filter and search like those made by DT or itables.

And they’re an HTML table with a bunch of JS on top. They are compiled into the HTML book and and do not require a server (though we host the books centrally to avoid having more than one version of the truth if the reports are updated).

1 Like

I’m 99% sure that the news unfortunately is that such things packages aren’t available in Julia at this moment.

I don’t have much experience with your particular problem, but I do know that sometimes when language wrappers do not work then there is luckily CSV, that is, store CSV in Julia and read it with R or vice versa.

1 Like

Does TableView do what you are asking for?

Ok, I’ll see if there is workaround with the intermediaries that works for now. It might also be worth asking some of the other authors how I might go about it if I was going to attempt to write something that would be compatible with existing tools.

Thanks for your time! :slight_smile:

Unfortunately, no - that’s the example that doesn’t end up in the book. It does seem like it’s the closest so I’ll see if I can fix the issue with the compilation environment.

I’ve been playing with it and…frustration. When I load the notebook file and execute it interactively, it’s fine, but when you export or nbconvert to html, it no longer can see the webio notebook extension that TableView needs.

1 Like

Maybe have a look at quarto, it’s a brilliant system for converting Markdown and notebooks (including IJulia notebooks) to different formats. It’s done by the RStudio people based on pandoc (like Bookdown I think). You can execute Julia code using notebooks, or with code blocks in Markdown files.

I don’t know if it does what you need, but it’s worth having a look at the project anyway :slight_smile:

3 Likes

That’s awesome! Long time user of RMarkdown here and what a happy journey it’s been. This looks like the next level to me and i look forward to creating new reports based on julia code as well.

1 Like

Same! I’ve documented my efforts here.

Thanks for bringing this to my attention I will def take a peek!

I am infuriatingly close. I am using RCall to generate a beautiful table in a standalone HTML file:

using RDatasets
using RCall

x = dataset("datasets", "mtcars");

@rput x;

R"

library(DT)

htmlwidgets::saveWidget(x %>% DT::datatable(.), 'result.html')

"

Thus, a more refined version of my question is “In ipynb, does anyone know how I can get a markdown cell or a Julia cell to display this HTML file?”

WebIO is out, I get the same thing from before in the books, I just recreate it myself:

using WebIO

htmlString = read("result.html", String)

Scope(dom=node(:p, htmlString))

Looks like I should ask the WebIO folks about this.

At least now I can take the partial victory of knowing I can likely get this to work by switching back to Rmd where I’d have cells-by-language or switch to Python where I’d have magics instead of calls from a library.

I might not be able to escape to Julia but I do now know I can at least escape to Python lol.

Kind of like escaping from Pepsi to Coke instead of Prosecco. :laughing:

You could avoid the R part by writing a translator to client-side HTML/JS, like Tabulator, which does not look difficult. I still don’t see how to inject that into a jupyter-book or weave page, but you could write a script to post-process the initial HTML outputs.

1 Like

LMAO that’s good. I’d much prefer to be working in Python over R so to me it’s more like escaping from Diet Pepsi to a PBR when I was looking for a Boston Lager lol.

I will look into this other angle and open a question issue on WebIO. Thanks all!