Hi,
Anyone knows how to capture the output of PrettyTables
in a Franklin page?
Of two examples below (second is from Franklin’s manual), the first shows the output via
PrettyTables
and it doesn’t show up in the generated html. The second example works fine.
Thanks
gmtread("mff_bb.txt")
\show{./code/ex1}
x = 5
println("hello")
x^2
\show{ex_show}
This should work:
```julia:ex
using PrettyTables
data = [1 2 3; 4 5 6]
io = IOBuffer() # hide
pretty_table(io, data;
header = ["Column 1", "Column 2", "Column 3"],
backend=Val(:html)
)
println("~~~" * String(take!(io)) * "~~~") # hide
```
\textoutput{ex}
this is what it looks like for me:
I hope it makes sense, feel free to open a PR in the demos if you think that would be useful! (file to edit for the demos).
1 Like
Thanks, using your idea I was able to make it kind of work
```julia:./code/ex1
using GMT, PrettyTables # hide
getpath4docs(file::String) = joinpath("..", "..", "..", "..", "..", file) # hide
io = IOBuffer() # hide
D = gmtread(getpath4docs("mff_bb.txt"))
pretty_table(io, D.data; header = D.colnames, backend=Val(:html)) # hide
println("~~~" * String(take!(io)) * "~~~") # hide
\textoutput{./code/ex1}
But I had to print explicitly the matrix into io
. What I was expecting was that simply typing gmtread(getpath4docs("mff_bb.txt"))
would have resulted in the same output. But probably the issue is that the function that does the printing (stolen from DataFrames
) does not use the backend=Val(:html)
Another way of putting this question is “How can we pretty print a DataFrame in Franklin?”
(And yes, these examples would be nice to have in the demos).
The next version of Franklin checks MIME type and shows output automatically based on MIME with a priority for HTML or SVG output depending on the object you’re trying to show (you can see this in action here). So this is already in, just not in the version you’re currently using.
With the current version though, you do have to generate the HTML explicitly then print ~~~$(the_html)~~~
and call textoutput
. For objects from packages that support HTML output, you can call show(io, MIME("html"), object)
.