Open RobertCProjects opened 3 years ago
I experienced the same issue. A quick workaround seems:
gt_table = countrypops %>%
gt(
rowname_col = "country_name",
groupname_col = "region"
)
gt:::as.tags.gt_tbl(gt_table)
Thanks for reporting this and sharing the screenshot as well! For sure, gt tables should detect the Jupyter notebook environment and emit HTML. I hope to get this working soon.
Answer above works. I do this to keep piping:
gts <- function(gt_table){
gt:::as.tags.gt_tbl(gt_table)
}
gt(head(mtcars)) %>%
gts()
Hi all, thanks for the solutions @bryanwhiting and @exoulster.
I'm running into a potentially related issue so I'm posting it here instead of opening a new issue.
When I export this R notebook in VSCode (with a gt table cell output) to PDF, instead of printing the table it prints the text Shiny tags cannot be represented in plain text (need html)
.
I run into this issue whether I use the built-in export to PDF:
...or run the following command from the command line:
jupyter nbconvert --to pdf "gt_table_demo.ipynb"
# data analysis imports
library(tidyverse)
library(magrittr)
# formatting tables
library(gt)
# color palettes
library(scales)
# create test data
data <- data.frame(
outcome_statement = c(
"This is a very long outcome statement which will require a wide column if it remains in one line",
"This is a second very long outcome statement which will require a wide column if it remains in one line",
"This is a third very long outcome statement which will require a wide column if it remains in one line"),
value_1 = c(1000,2000,3000),
value_2 = c(450000,300,5000),
value_3 = c(8500, 750, 25)
)
gts
function# create gt table output
data %>%
gt() %>%
tab_options(
column_labels.font.weight = "bold",
table.width = pct(100)
) %>%
tab_style(
style = cell_borders(
sides = c("bottom", "right"),
color = "#bfbfbf"
),
locations = cells_body(
columns = everything(),
rows = everything()
)
) %>%
tab_header(
title = "Three Values for Different Outcomes"
) %>%
data_color(
columns = c(
value_1,
value_2,
value_3),
#colors = col_bin(colorRamp(c("#fff8eb", "#fdb734"), interpolate="spline"), domain = c(0,5005), bins = 6)
colors = col_factor(colorRamp(c("#fff8eb", "#fdb734"), interpolate="spline"), domain = NULL)
) %>%
tab_footnote(
footnote = "Description of Value 1",
locations = cells_column_labels(
columns = value_1
)
) %>%
tab_footnote(
footnote = "Description of Value 2",
locations = cells_column_labels(
columns = value_2
)
) %>%
tab_footnote(
footnote = "Description of Value 3",
locations = cells_column_labels(
columns = value_3
)
) %>%
cols_label(
outcome_statement = "Outcome Statement",
value_1 = "Value 1",
value_2 = "Value 2",
value_3 = "Value 3"
) %>%
gts()
If I don't use the gts
helper function, here's the output in PDF:
I've found a decent workaround for now: using the weasyprint pdf-engine for pandoc:
pip install weasyprint
pandoc gt_table_demo.ipynb --pdf-engine=weasyprint -o gt_table_demo.pdf
Output PDF contains (mostly correctly) formatted gt table:
Using R package gt() example code (from https://gt.rstudio.com/) within Anaconda Jupyter notebook R (4.1.1) environment outputs lots of code but not properly formatted table. Similar issue with other example code.