How to make Pluto.jl load all rows of a DataFrame

I have a DataFrame with ~100 rows. How do I make the DataFrame be displayed with all of its rows within Pluto.jl? The default view is this:

What I’d like is this:


where all elements are visible within a little scrollable window.

Essentially, I just want to skip clicking the “⋮ more” button until all of the rows are displayed and just have it already there when the DataFrame is displayed.

I’ve looked into some solutions about setting the COLUMNS and ROWS environment variables, and about using WithIOContext from PlutoUI.jl, but that doesn’t really provide the results I want. A MWE is given as follows (Manifest omitted for brevity):

### A Pluto.jl notebook ###
# v0.20.4

using Markdown
using InteractiveUtils

# ╔═╡ 94d941ef-a445-47a7-87f1-7affe3617ba5
using Pkg

# ╔═╡ 35672f36-26db-4dc9-a9ee-49537cc3e3f6
using DataFrames

# ╔═╡ 3cd9c058-fe7b-486c-81b8-838ffc1b728c
using PlutoUI

# ╔═╡ 50972f08-1e52-4b55-b013-62993a45c617
Pkg.status |> with_terminal

# ╔═╡ 247eaffe-cbf5-41b3-bfd4-4fbfa9b253a7
datapoints = 130;

# ╔═╡ acd439b8-dd95-4a7c-989e-96913178abd9
df = DataFrame(
    :particle_type => rand(1:4, datapoints),
    :momentum => randn(datapoints),
    :total_energy => randn(datapoints),
    :entering_particle_flux => randn(datapoints),
);

# ╔═╡ fe3f355d-ce45-48a1-8e35-9bfb17dd2a8a
df

# ╔═╡ c1f41012-211d-4f40-847d-415f5385cf32
WithIOContext(df, :displaysize => (9999,9999))

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"

[compat]
DataFrames = "~1.7.0"
PlutoUI = "~0.7.61"
"""

# ╔═╡ Cell order:
# ╠═35672f36-26db-4dc9-a9ee-49537cc3e3f6
# ╠═94d941ef-a445-47a7-87f1-7affe3617ba5
# ╠═3cd9c058-fe7b-486c-81b8-838ffc1b728c
# ╠═50972f08-1e52-4b55-b013-62993a45c617
# ╠═247eaffe-cbf5-41b3-bfd4-4fbfa9b253a7
# ╠═acd439b8-dd95-4a7c-989e-96913178abd9
# ╠═fe3f355d-ce45-48a1-8e35-9bfb17dd2a8a
# ╠═c1f41012-211d-4f40-847d-415f5385cf32
# ╟─00000000-0000-0000-0000-000000000001

1 Like

I believe you have to use the BrowseTables package and print the dataframe with HTMLTable(df)

1 Like

@fonsp - Any ideas? This is what I got when I tried the example in the docstring for WithIOContext.

It displays all 100 columns, but it omits some rows and you don’t get an option to click on “More” to see them.

You can use pretty_table but then you have problem with columns.
The answer I gave above is wrong, this has changed. Interesting topic.

There are several ways to do this. My personal favorite is naturally this tiny package that I wrote:

You can either dump the whole table or have rows dynamically shuffled from julia for very large tables, and if you use the showtable function directly you the returned value is an observable you can @bind to get the selected rows.

It’s not in the repos but you can add it directly with the above url.

Alternatively i think you can set some parameter to control how large it can get before getting folded. i forgot where right now, but the code that register overrides on the pluto side should have the answer.

Another alternative would be to use eg htl package to directly construct the html for a table from the dataframe, which should be rather simple since the values should just interpolate.

An even quicker & dirtier solution would be to either directly print or @info the df.

Personally i just use my package above and see nice tables with selectable rows.

3 Likes

Saw the similar post here. It works for me.

using HypertextLiteral, PrettyTables
html_table = pretty_table(String, df, backend = Val(:html))
scrollable_table = @htl("""
    <div style="max-height: 400px; overflow-y: auto; border: 1px solid #ccc;">
        $(HTML(html_table))
    </div>
""")
scrollable_table