# Capturing PrettyTables output in Franknlin

**URL:** https://discourse.julialang.org/t/capturing-prettytables-output-in-franknlin/83403
**Category:** General Usage
**Tags:** franklin
**Created:** [June 27, 2022, 1:28pm UTC](https://discourse.julialang.org/t/capturing-prettytables-output-in-franknlin/83403 "2022-06-27T13:28:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [June 27, 2022, 1:28pm UTC](https://discourse.julialang.org/t/capturing-prettytables-output-in-franknlin/83403/1 "2022-06-27T13:28:33Z")

</div>

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

```julia
gmtread("mff_bb.txt")

```

\show{./code/ex1}

```julia
x = 5
println("hello")
x^2

```

\show{ex\_show}

---

<div class="post-metadata">

### Author: ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)
#### Post date: [June 27, 2022, 3:49pm UTC](https://discourse.julialang.org/t/capturing-prettytables-output-in-franknlin/83403/2 "2022-06-27T15:49:53Z")

</div>

This should work:

````julia
```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:

 ![Screenshot 2022-06-27 at 17.48.04](https://global.discourse-cdn.com/julialang/original/3X/9/8/98f4eac00c3d7f285ded3d9b27c7f76d562daabc.png)

I hope it makes sense, feel free to open a PR in [the demos](https://franklinjl.org/demos/) if you think that would be useful! ([file to edit for the demos](https://github.com/tlienart/Franklin.jl/blob/master/demos/index.md)).

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [June 27, 2022, 7:21pm UTC](https://discourse.julialang.org/t/capturing-prettytables-output-in-franknlin/83403/3 "2022-06-27T19:21:36Z")

</div>

Thanks, using your idea I was able to make it kind of work

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/d/4ddca9e003dc25cfc41104a828f5fd789217e3e8.png)

````julia

```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](https://github.com/GenericMappingTools/GMT.jl/blob/master/src/show_pretty_datasets.jl#L135) 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_).

---

<div class="post-metadata">

### Author: ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)
#### Post date: [June 27, 2022, 10:12pm UTC](https://discourse.julialang.org/t/capturing-prettytables-output-in-franknlin/83403/4 "2022-06-27T22:12:09Z")

</div>

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](https://tlienart.github.io/Xranklin.jl/syntax/code-2/#using_packages)). 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)` .
