gforge / htmltable Goto Github PK
View Code? Open in Web Editor NEWAn R package for generating advanced tables
An R package for generating advanced tables
Is there a programming way to export many HTML tables into word?
It is nice to have the copy paste feature to word directly. However, people may get a request to repeatedly update some tables into word. I am wondering if there is a way to do it automatically.
Package looks gorgeous! It's not clear how to group rows and columns that do not lie next to one another.
htmlTable fails "unable to load shared object /stringi/libs/stringi.so : libicui18n.so.52 during lazy load. Any way to fix this?
Thanks.
Hi, if i add image html tag in data.frame column in version htmlTable htmlTable_1.11.0, and send this result over maiR ti mail i have this result:
sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=Russian_Russia.1251
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] htmlTable_1.11.0 mailR_0.4.1 bigrquery_0.4.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 rstudioapi_0.7 knitr_1.17 bindr_0.1 magrittr_1.5
[6] hms_0.4.0 progress_1.1.2 R6_2.2.2 rlang_0.1.4 stringr_1.2.0
[11] httr_1.3.1 dplyr_0.7.4 tools_3.4.3 checkmate_1.8.5 R.oo_1.21.0
[16] DBI_0.7 htmltools_0.3.6 openssl_0.9.9 yaml_2.1.15 assertthat_0.2.0
[21] digest_0.6.12 tibble_1.3.4 bindrcpp_0.2 rJava_0.9-9 readr_1.1.1
[26] purrr_0.2.4 tidyr_0.7.2 htmlwidgets_0.9 R.utils_2.6.0 curl_3.0
[31] glue_1.2.0 stringi_1.1.6 compiler_3.4.3 prettyunits_1.0.2 backports_1.1.1
[36] R.methodsS3_1.7.1 jsonlite_1.5 pkgconfig_2.0.1
And after a roll back to verion htmlTable_1.9 i get correctly table in my mail.
sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=Russian_Russia.1251
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] htmlTable_1.9 mailR_0.4.1 bigrquery_0.4.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 rstudioapi_0.7 knitr_1.17 bindr_0.1 magrittr_1.5
[6] hms_0.4.0 progress_1.1.2 R6_2.2.2 rlang_0.1.4 stringr_1.2.0
[11] httr_1.3.1 dplyr_0.7.4 tools_3.4.3 checkmate_1.8.5 R.oo_1.21.0
[16] DBI_0.7 htmltools_0.3.6 openssl_0.9.9 yaml_2.1.15 assertthat_0.2.0
[21] digest_0.6.12 tibble_1.3.4 bindrcpp_0.2 rJava_0.9-9 readr_1.1.1
[26] purrr_0.2.4 tidyr_0.7.2 htmlwidgets_0.9 R.utils_2.6.0 curl_3.0
[31] glue_1.2.0 stringi_1.1.6 compiler_3.4.3 prettyunits_1.0.2 backports_1.1.1
[36] R.methodsS3_1.7.1 jsonlite_1.5 pkgconfig_2.0.1
My r script:
library(bigrquery)
library(mailR)
library(htmlTable)
#Send query ti BigQuery
rating <- query_exec(query =query,
project = projectID)
#Create photos
rating$avatar_img <- paste0('<img src="',ifelse(substr(rating$avatar_img,1,4) == "http",rating$avatar_img, paste0("https://netpeak.net",rating$avatar_img)),'" width="100" alt="lorem">')
rating_html <- htmlTable(rating,
col.rgroup = c("cadetblue2", "lightcyan"),
rnames = FALSE)
#HTML body of email message
msg <- paste0('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Rating</title>
<style type="text/css">
</style>
</head>
<body>
<center><img src="https://netpeak.net/blog/img/netpeak/logo-blog-01.svg" alt="lorem"></a></center>
<h1>',txt,'</h1>
',rating_html,
'<hr><p></p>
</hr>
</body>
</html>')
#Send letter
send.mail(from = "BI Netpeak <[email protected]>",
to = c("[email protected]"),
subject = paste0("Netpeak Blog Ratings: Most viewed posts daily rating by ",format(Sys.Date(), "%d.%m.%Y")),
body = msg,
encoding = "utf-8",
inline = FALSE,
html = TRUE,
smtp = list(host.name = "smtp.gmail.com",
port = 465,
user.name = "GOOGLE_USER",
passwd = "PASSWORD",
ssl = TRUE),
authenticate = TRUE,
send = TRUE)
Can you fix this issure?
Describe the bug
Hi, Thank you for this wonderful package.
I have noticed that - the tidyHtmlTable wrapper does not allow rnames or rgroup to accept anything other than a character string. Thus, nested row groups are not able to be passed to the function.
To Reproduce
tidy.DF_FULL %>%
tidyHtmlTable(x = .,
header = "ColumnLevel02",
cgroup1 = "ColumnLevel01",
value = "formattedValue",
rnames = "RowLevel03",
rgroup = c("RowLevel01", "RowLevel02"))
creates the following error:
Error in argument_checker(x, value = value, header = header, rnames = rnames, :
The following parameters must be of type character: rgroup
Expected behavior
Row Level 2 would be nested within Row Level 1 - just like Row Level 3 is nested within Row Level 2
i.e. Rows would be nested Level 1 > Level 2 > Level 3
Versions (please complete the following information):
Additional context
The Tidy Html Table wrapper is fantastic and works perfectly in all over situations. It is simply not responding to multiple nested groups. Is it possible to get an interim data structure out that could be manipulated before rendering in html?
With R 3.3.3 and all latest stuff, the print(object, type="HTML",file="myfile.html".useViewer=FALSE) prints the htlml object inline.,
The doc about css.cell is not correct grammatically when it comes to the part about css.cell being a matrix.
css.cell: The css.cell element allows you to add any possible CSS style
to your table cells. If you provide a vector the vector it is
assummed that the styles should be repeated throughout the
columns. If you provide a matrix of the same size as your ‘x’
argument. If have ‘ncol(x) + 1’ the first row will correspond
to the rowname style. Correspondingly if the size is ‘nrow(x)
+ 1’ it is assummed that the first row is the header row.
Regardless, I did not figure out how to specify style for the header of a table using css.cell. Can you please add provide an example? Thanks.
For some reason the align
parameter in the htmlTable function makes it impossible to specify a text-align
in the css.cell
matrix. See the example and the result.
library(htmlTable)
data <- data.frame(aaaaaa = letters[1:5],
baaaaa = LETTERS[1:5])
css_cell <- matrix('background-color: red;text-align: "right"', nrow = 5, ncol = 2)
htmlTable(data, css.cell = css_cell)
If this is the expected behaviour that is fine, but it was a bit surprising that all the css style attributes were working except this one 😅
Hi,
First of all, thank you for great package.
I found strange behavior when I have a dollar sign in some cells of data.frame. When I knit such data.frame with htmlTable I get broken html. Note that this bug arises only when knitting. Rendering the same table in the RStudio viewer/RNotebook gives absolutely correct result.
Code for reproducing:
---
title: "Untitled"
date: '14 april 2018 г '
output: html_document
---
```{r }
library(htmlTable)
## incorrect rendering
my_df = data.frame(
row_labels = c("!", "!=", "$", "$<-", "%in%", "$", "(", "*"),
a1 = 1:8,
a2 = 11:18,
stringsAsFactors = FALSE)
htmlTable(my_df, escape.html = TRUE)
htmlTable(my_df, escape.html = FALSE)
## correct rendering after removing some dollar signs
my_df = data.frame(
row_labels = c("!", "!=", "", "<-", "%in%", "$", "(", "*"),
a1 = 1:8,
a2 = 11:18,
stringsAsFactors = FALSE)
htmlTable(my_df, escape.html = TRUE)
htmlTable(my_df, escape.html = FALSE)
Session info:
## R version 3.4.3 (2017-11-30)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 16299)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=Russian_Russia.1251 LC_CTYPE=Russian_Russia.1251
## [3] LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C
## [5] LC_TIME=Russian_Russia.1251
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] compiler_3.4.3 backports_1.1.2 magrittr_1.5 rprojroot_1.3-2
## [5] tools_3.4.3 htmltools_0.3.6 yaml_2.1.16 Rcpp_0.12.15
## [9] stringi_1.1.7 rmarkdown_1.9 knitr_1.20 stringr_1.3.0
## [13] digest_0.6.15 evaluate_0.10.1
> data.frame("äüöÄÖÜß")
X.äüöÄÖÜß.
1 äüöÄÖÜß
The above works fine, the following does unfortunately not:
htmlTable(data.frame("äüöÄÖÜß"))
X.�������.
1 �������
What can I do? Thank you!
Why are spacer cells added between column groups? Is there a way to assign column groups without spacer cells? For the application I'm using your package for when those blank cells are added the CSS properties that I apply externally really do not jive well with the blank spaces in there. I tried to modify the htmlTable function on my local machine to see if I could provide a solution but I was not able to solve the issue.
Thanks! (Code is below: lines 527-529. At least that's where I think those blank columns are being added)
# With multiple rows in cgroup we need to keep track of
# how many spacer cells occur between the groups
cgroup_spacer_cells <- rep(0, times=(ncol(x)-1))
The new RStudio notebook allows inline tables but this requires that the function returns knitr::asis_output
instead of using the viewer. Unfortunately it currently ignores interactive use of knit_print and it doesn't have any obvious ways for detecting when running within a notebook.
Take the MWE:
library(htmlTable)
customTable <- function(x, css = c("custom-table", "custom-table-small")) {
css.table <- match.arg(css)
x <- addHtmlTableStyle(x, css.table = css.table)
htmlTable(x)
}
customTable(x = mtcars)
I basically want to add different values for css.table
. My real customTable
is a little more complex. I get the error thet css.table
cannot be found. I guess that this is a scoping issue. Is it intentional and what is the work-around besides adding the styles outside of my customTable
function?
I am using the current developer branch feature/flexible_spacer_cells
.
Hi Max,
txtRound()
returns unexpected results for vectors:
> txtRound(c(1, 2, 3, 4))
[1] "1" "2" "3" "4"
Warning message:
In if (is.na(x)) return(txt.NA) :
the condition has length > 1 and only the first element will be used
> txtRound(c(1, 2, 3, NA))
Error in if (round(v, d) == 0) v <- 0 :
missing value where TRUE/FALSE needed
In addition: Warning message:
In if (is.na(x)) return(txt.NA) :
the condition has length > 1 and only the first element will be used
> txtRound(c(NA, NA, NA, NA))
[1] ""
Warning message:
In if (is.na(x)) return(txt.NA) :
the condition has length > 1 and only the first element will be used
The first case should not result in a warning; the second case should not fail; the third case should return a vector of length 4. My guess is that this is caused by line 218-219 in txtRmt.R
. I can submit a patch later this week if you're interested.
with kind regards,
Peter
https://github.com/gforge/htmlTable/blob/master/R/txtFrmt.R
line 246-248:
if (digits.nonzero < digits) {
stop("The digits.nonzero must be smaller than digits")
}
Should be "must be larger than digits".
Thanks for this package. I was just trying it with a data frame and I found an issue:
library(htmlTable)
data(iris)
head(iris)
htmlTable(iris)
The generated table shows the Species column as an integer column. I expected it to be shown as a character.
As a workaround I can convert the factor to character
iris_char <- iris
iris_char$Species <- as.character(iris_char$Species)
htmlTable(iris_char)
But it would be nice if htmlTable did that for me. Is it feasible to implement this?
Firstly, thanks for this great package, really like the functionality.
The total
parameter in htmlTable
is very handy for when I have a total final row. Is there an easy (or hard) way to do the same for the last column? Is it something that could be incorporated in the total
parameter in future?
Thanks.
Hi Max,
htmlTable() creates three-line tables as its default results. But i want to draw all td borders in my tables.
My table using this function is below:
2015 | 2016 | 2017 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
TypeName | mean | sd | cv | mean | sd | cv | mean | sd | cv | |||
Type1 | 98.73 | 11.02 | 0.11 | 101.22 | 10.41 | 0.10 | 95.22 | 13.00 | 0.14 | |||
Type2 | 98.53 | 26.28 | 0.27 | 93.11 | 27.47 | 0.30 | 90.45 | 26.85 | 0.30 | |||
Type3 | 98.16 | 26.51 | 0.27 | 98.25 | 27.61 | 0.28 | 96.37 | 28.13 | 0.29 | |||
Type4 | 66.63 | 14.94 | 0.22 | 64.30 | 12.13 | 0.19 | 61.86 | 11.91 | 0.19 | |||
Type5 | 74.66 | 12.38 | 0.17 | 49.27 | 13.57 | 0.28 | 58.46 | 13.40 | 0.23 | |||
Type6 | 54.64 | 12.64 | 0.23 | 52.98 | 12.67 | 0.24 | 44.16 | 11.84 | 0.27 | |||
Type7 | 487.38 | 98.28 | 0.20 | 458.54 | 89.22 | 0.19 | 446.51 | 86.89 | 0.19 |
Blank columns among cgroups are not what i want.
So,two questions:
And this is what i want:
TypeName | 2015 | 2016 | 2017 | ||||||
---|---|---|---|---|---|---|---|---|---|
mean | sd | cv | mean | sd | cv | mean | sd | cv | |
Type1 | 98.73 | 11.02 | 0.11 | 101.22 | 10.41 | 0.10 | 95.22 | 13.00 | 0.14 |
Type2 | 98.53 | 26.28 | 0.27 | 93.11 | 27.47 | 0.30 | 90.45 | 26.85 | 0.30 |
Type3 | 98.16 | 26.51 | 0.27 | 98.25 | 27.61 | 0.28 | 96.37 | 28.13 | 0.29 |
Type4 | 66.63 | 14.94 | 0.22 | 64.30 | 12.13 | 0.19 | 61.86 | 11.91 | 0.19 |
Type5 | 74.66 | 12.38 | 0.17 | 49.27 | 13.57 | 0.28 | 58.46 | 13.40 | 0.23 |
Type6 | 54.64 | 12.64 | 0.23 | 52.98 | 12.67 | 0.24 | 44.16 | 11.84 | 0.27 |
Type7 | 487.38 | 98.28 | 0.20 | 458.54 | 89.22 | 0.19 | 446.51 | 86.89 | 0.19 |
So how can i do that using htmlTable()?
Thanks so much!
Qian
I have this code which produces a table with a warning. It seems nsmall is passed to format
htmlTable(txtInt(ATOMS_AGG, language = "en", html = TRUE, nsmall = 4),
header = ATOMSHeader,
rnames = FALSE,
css.cell = rbind(rep(
"font-size: 1em; padding-left: 1em; padding-right: 1em;",
times=ncol(ATOMS_AGG)))
)
Warning messages:
1: In FUN(X[[i]], ...) :
The function can only be served integers, '0.3495' is not an integer. There will be issues with decimals being lost if you don't add the nsmall parameter.
here is the dataframe
structure(list(Orig_Bal = 5284699, Curr_Balance = 1847112, Num_Loans = 16866197L,
Num_Pools = 184290L, Factor = 0.3495, GWac = 3.89, Age = 34,
Wam = 289, RScore = 487, DScore = 848, CPR_1M = 15.06, CPR_3M = 41.42,
CPR_6M = 64.87, ATOMS_MTDRTN = 0.0057), class = "data.frame", row.names = c(NA,
-1L), .Names = c("Orig_Bal", "Curr_Balance", "Num_Loans", "Num_Pools",
"Factor", "GWac", "Age", "Wam", "RScore", "DScore", "CPR_1M",
"CPR_3M", "CPR_6M", "ATOMS_MTDRTN"))
Hi there, I'm trying to render the following doc as word_document but the table doesn't seem to be working, here is the Rmd doc that I wrote
---
title: "Untitled"
author: "George G. Vega Yon"
date: "September 8, 2015"
output: word_document
---
```{r}
library(htmlTable)
mx <-
matrix(ncol=6, nrow=8)
rownames(mx) <- paste(c("1st", "2nd",
"3rd",
paste0(4:8, "th")),
"row")
colnames(mx) <- paste(c("1st", "2nd",
"3rd",
paste0(4:6, "th")),
"hdr")
for (nr in 1:nrow(mx)){
for (nc in 1:ncol(mx)){
mx[nr, nc] <-
paste0(nr, ":", nc)
}
}
htmlTable(mx,
total = "tspanner",
css.total = c("border-top: 1px dashed grey;",
"border-top: 1px dashed grey;",
"border-top: 1px solid grey; font-weight: 900"),
tspanner = paste("Spanner", LETTERS[1:3]),
n.tspanner = c(2,4,nrow(mx) - 6))
Additional info
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] htmlTable_1.3 autoreport_0.15.8 xtable_1.7-4
loaded via a namespace (and not attached):
[1] Rcpp_0.12.0 lubridate_1.3.3 digest_0.6.8 dplyr_0.4.3 assertthat_0.1
[6] R6_2.1.0 plyr_1.8.3 DBI_0.3.1 formatR_1.2 magrittr_1.5
[11] evaluate_0.7.2 stringi_0.5-5 rmarkdown_0.8 tools_3.2.2 stringr_1.0.0
[16] yaml_2.1.13 parallel_3.2.2 htmltools_0.2.6 memoise_0.2.1 knitr_1.11
Using options(table_counter=T) leads to tables being numbered 1,3,5...
I think the table counter is being incremented twice per table - once in htmlTable.R (line 484) and then again in the htmlTable_helpers.R (prTblNo).
It is very easy to do superscript in SAS in headers/footnotes or in a dataset. And it is very useful feature in clinical reporting! Unfortunately, I cannot find it in R. Is it possible in the htmlTable package?
When you specify a vector for the digits
argument with a length smaller than the number of columns, a warning is thrown instead of an error. Compare:
test_mx <- matrix(c(1, 1.11, 1.25,
2.50, 2.55, 2.45,
3.2313, 3, pi),
ncol = 3, byrow=TRUE)
# works as expected
txtRound(test_mx, digits = 1)
# throws an error, as expected
txtRound(test_mx, digits = rep(1, 4))
# only throws a warning
txtRound(test_mx, digits = rep(1, 2))
I thought it might be useful include an interface for the htmlTable function that would allow mapping columns from a data.frame to specific htmlTable parameters such as rnames, headers, tspanner, rgroups, etc similar to ggplot2. That said, I built a wrapper function to exactly this (albeit with standard evaluation and less compatibility with tbl_df's.)
I don't know if you see this as within the scope of the package, but so I built a small package to contain this wrapper function.
If you style each cell with the CSS format "mso-number-format", then compatibility with Excel is increased. I did not know this before this SO-question. So maybe it is a good idea to put in the manual :)
Use this css-matrix
css_matrix <- matrix( data = "mso-number-format:\"\\@\"", nrow = nrow(df), ncol = ncol(df))
SO question:
https://stackoverflow.com/questions/48151491/convert-html-table-to-excel-using-vba
Hi
Is it possible to print htmlTable objects directly to a word file? Have searched the manual and vignettes but without any luck.
Thanks
I'm not sure if this only happens on Windows.
This is the result in Windows (with R 3.5.0 x64):
htmlTable(data.frame(a="camión"))
1 | cami�n
The non-ANSI characters always get converted to strange symbols �.
Quite often we need to be able to add CSS to the column header row to either change the font size or add padding. As far as I can tell there is no existing option to do this
Hi,
I'm trying to render a table in a Shiny app using the htmlTable
function. I know renderhtmlTableWidget
and htmlTableWidgetOutput
exist, but they don't work for me. (Neither does datatable.) My data is a csv with contains a column of scripts like: <script type="text/javascript" src="https://forvo.com/_ext/ext-prons.js?id=55464"></script>
. The scripts render with htmlTable
outside of Shiny, but I can't even get the table to render with the Shiny runtime (I'm using Flexdashboard).
I just wanted to know if there's a way to get this to work. I've tried combinations of renderTable
, renderDataTable
etc. Here's a snippet of the code I have:
data <- reactive({
df %>%
filter(
Position == input$pos,
#Name == input$Name,
Country == input$country
)
})
output$tbl <- renderTable(
htmlTable(
data() %>% select(-Group, -Clr),
align='clc',
col.rgroup = data() %>% pull(Clr),
css.cell = "font-size: 12px",
css.table = "margin-top: .5em; margin-bottom: .5em; margin: auto; padding: 0px;
width: 80%"
)
)
tableOutput('tbl')
Which produces this:
`<table class='gmisc_table' style='border-collapse: collapse; margin-top: .5em; margin-bottom: .5em; margin: auto; padding: 0px; width: 80%' > <thead> <tr> <th style='border-bottom: 1px solid grey; border-top: 2px solid grey;'> </th> <th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Position</th> <th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Name</th> <th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Country</th> </tr> </thead> <tbody> </tbody> </table>`
Hi,
I was wondering if it is currently possible to have the HTML table paginated... Showing for instance 10 rows and a previous/next page button.
I cannot find the option and it is a handy feature for long tables...
Thanks and sorry if I have missed it!
This simple example does not generate proper HTML code because it does not replace >
with >
:
htmlTable::htmlTable(data.frame(a = ">3"), rnames = FALSE)
Actual result:
<table class='gmisc_table' style='border-collapse: collapse; margin-top: 1em; margin-bottom: 1em;' >
<thead>
<tr>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>a</th>
</tr>
</thead>
<tbody>
<tr>
<td style='border-bottom: 2px solid grey; text-align: center;'>>3</td>
</tr>
</tbody>
</table>
Expected:
<table class='gmisc_table' style='border-collapse: collapse; margin-top: 1em; margin-bottom: 1em;' >
<thead>
<tr>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>a</th>
</tr>
</thead>
<tbody>
<tr>
<td style='border-bottom: 2px solid grey; text-align: center;'>>3</td>
</tr>
</tbody>
</table>
These characters should be escaped.
<
represents the < sign.>
represents the > sign.&
represents the & sign.Probably a escape=TRUE
argument should be added, so the character escaping can be skipped if, for instance, I want to include HTML code inside the table.
Hi Max,
I can't get htmlTable to use the RStudio viewer pane anymore (version 1.9). The class of a htmlTable object is now "html" "htmlTable" "character"
Everything works fine after manually setting the class to "htmlTable" "character"
. Is it possible that the fix for issue #26 caused this?
thanks
Peter.
Hi Max,
Do you foresee implementing nested row-grouping similar to what is available for columns?
BTW: thanks very much for creating this package. I had been on the lookout for something with this functionality, and this works great!
Hello,
I have been using htmlTables to display data for a Shiny application. I don't have that much information in the tables so I'm sized them to include all data. Is there a way to easily remove the "Show X Entries" at the top left of the table?
Thank you
When using txtRound to round numbers in scientific notation, txtRound would only extract the numeric value and ignore the e-notation. For example, both txtRound('1.693213e2', digits = 3)
and txtRound('1.693213e-2', digits = 3)
return "1.693"
.
It would be most excellent to gain control over the overall table borders. This would involve changing the api, though, replacing ctable
with something like tableborders = c("none", "single", "double")
. Lower priority, but it could perhaps also allow users to pass a list (?) where the first element is the css for the top boarder and the second element is the cc for the bottom border.
Is a change to the ctable syntax something you would be open to?
It would be nice if tableHTML conformed to the tidyverse custom of working with magrittr chaining. So for example, it would be nice to say:
df %>% tableHTML(rownames = FALSE)
Instead of the current:
df %>% tableHTML(., rownames = FALSE)
(GREAT package, by he way!)
When colnames are written with non-english, result of htmlTable have broken column names.
How can I fix it?
If dataset has one row only and I try to use css.cell with matrix where nrow is one greater than the number of rows (to apply the formatting also to header), the function htmlTable
gives an error.
> d = iris[1, ]
> cssMatrix = matrix("padding-left: .5em;", nrow = nrow(d) + 1, ncol = ncol(d))
> htmlTable(d, css.cell = cssMatrix)
Error in css.cell[row_nr, ] : incorrect number of dimensions
The same code works if there are more rows. Probably, the error is caused by a missing drop = FALSE
when filtering the rows.
I was running a report that accidentally tried to pass a dataframe with zero rows to htmlTable(). That generated the following error: Error in css.cell[row_nr, ] : subscript out of bounds.
I added error trapping to my code, but you should consider seq_along instead of for (nr in 1:nrow(x)).
thanks for a great package.
hi,
the latest htmlTable
adds a dependency (import) on tidyr
, which results in an additional 20 meg of dependencies requiring to be installed. this in turn has a non-trivial impact on the packages which in turn depend on htmlTable
. for example, Hmisc
imports htmlTable
, and Hmisc
is imported by a lot of packages, so this change has far reaching consequences.
i myself am coming from gamlj
imports lmerTest
imports Hmisc
imports htmlTable
imports tidyr
.
is it feasible for htmlTable
to be done in such a way that tidyr
is a suggests rather than an import?
with thanks, and thanks for all your work
The htmlTable
function raise an error when the user want to display a dataframe of one row when the css.cell
argument is specified as a matrix of two rows (one for the header and one for the data).
For example:
myDF <- data.frame(X = rnorm(1),
Y = 5*rnorm(1),
Z = c("toto"))
htmlTable(myDF,
css.cell = rbind(rep("padding-right: 2em;",
times=ncol(outTable)),
matrix(rep("padding-right: 1em;",
times=ncol(myDF)*nrow(myDF)),
ncol=ncol(myDF),
nrow=nrow(myDF))))
error message:
Error in css.cell[row_nr, ] : incorrect number of dimensions
It works fine when the dataframe has more than one row.
Session information:
Package htmlTable version 1.11.2
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1 )
I have a large dataframe which I want to make htmlTable of. Why is htmlTable so long compared to xtable. Following code takes only couple of seconds with xtable, while htmlTable takes about a minute to finish?
library(htmlTable)
library(xtable)
output <- matrix(1:62744,
ncol=44)
temp <- htmlTable(output) # couples of secends
tempXtable <- print(xtable::xtable(output), type="html") #takes about one minute, why ???
from the docs: "You can also force the function to call a specific viewer by setting this to a viewer function, e.g. useViewer = utils::browseUrl if you want to override the default RStudio viewer."
I was trying to figure a way to apply classes to individual rows. I was testing the approach based on the statement in the documentation that
If
css.cell
is a vector, it’s assumed that the styles should be repeated throughout the columns (that is, each element incss.cell
specify the style for the whole row of ’x’).
However, when I run the following
htmlTable(mtcars, rnames = FALSE, css.cell = paste0("row-class-", mtcars$cyl))
I get the following error
Error in prPrepareCss(x, css = css.cell, rnames = rnames, header = header) :
The length of your css.cell vector '32' does not correspond to the column length '11' (there are no rownames)
What am I missing?
Thanks for this package, it is great. Some questions about css.cell. In order to set it directly I need to insert a semi-colon at the start of my formatting string. Here is an example, I want the column named "M" in my data frame to be bold, so I create a second data frame containing the CSS formatting (in this case "font-weight: bold") in the relevant cells. In the output I get: 123
The extra "M: " makes the "font-weight: bold;" not render. So instead, I use "; font-weight: bold" and it renders correctly. In all cases the column name with a colon appears as the first entry in the style string. Am I using this wrong? Second, Is there a way to to directly set the CSS class for a cell rather than use the style? I don't need this necessarily, but was curious. Thanks again for this great tool!
Hi Max,
Wondering if htmlTable() can allow for conditional formatting of a row, column, or value? It seems from reading the vignettes this could be a possibility?
Scott
I have some tables that have the Date class, but have been changed to numeric with htmlTable
.
Is it possible to retain the date/time classes (POSIXct, Date, chron, etc.) when the htmlTable is printed?
Thank you.
Irucka Embry
I looked through the documentation but did not find an option that suits my needs.
When adding grouped headers using cgroup
and n.cgroup
I want to have borders to the left and right of those grouped columns.
I ended up extracting the raw HTML table code, parsing it using xml2
, use the n.cgroup
indices to identify the td
elements to which I need to add the CSS border styles and return the modified HTML code into the htmlTable object.
did I miss anything or is this the only way to go?
checking Rd cross-references ... NOTE
Package unavailable to check Rd xrefs: ‘pxweb’
checking examples ... ERROR
Running examples in ‘htmlTable-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: htmlTable
> ### Title: Outputting HTML tables
> ### Aliases: htmlTable htmlTable.default knit_print.htmlTable
> ### print.htmlTable
>
> ### ** Examples
>
> # A simple output
> output <- matrix(1:4,
+ ncol=2,
+ dimnames = list(list("Row 1", "Row 2"),
+ list("Column 1", "Column 2")))
> htmlTable(output)
<table class='gmisc_table' style='border-collapse: collapse;' >
<thead>
<tr>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey;'> </th>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Column 1</th>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td style='text-align: left;'>Row 1</td>
<td style='text-align: center;'>1</td>
<td style='text-align: center;'>3</td>
</tr>
<tr>
<td style='border-bottom: 2px solid grey; text-align: left;'>Row 2</td>
<td style='border-bottom: 2px solid grey; text-align: center;'>2</td>
<td style='border-bottom: 2px solid grey; text-align: center;'>4</td>
</tr>
</tbody>
</table>>
> # An advanced output
> output <-
+ matrix(ncol=6, nrow=8)
>
> for (nr in 1:nrow(output)){
+ for (nc in 1:ncol(output)){
+ output[nr, nc] <-
+ paste0(nr, ":", nc)
+ }
+ }
>
> htmlTable(output, align="r",
+ header = paste(c("1st", "2nd",
+ "3rd", "4th",
+ "5th", "6th"),
+ "hdr"),
+ rnames = paste(c("1st", "2nd",
+ "3rd",
+ paste0(4:8, "th")),
+ "row"),
+ rgroup = paste("Group", LETTERS[1:3]),
+ n.rgroup = c(2,4,nrow(output) - 6),
+ cgroup = rbind(c("", "Column spanners", NA),
+ c("", "Cgroup 1", "Cgroup 2†")),
+ n.cgroup = rbind(c(1,2,NA),
+ c(2,2,2)),
+ caption="Basic table with both column spanners (groups) and row groups",
+ tfoot="† A table footer commment",
+ cspan.rgroup = 2,
+ col.columns = c(rep("none", 2),
+ rep("#F5FBFF", 4)),
+ col.rgroup = c("none", "#F7F7F7"),
+ css.cell = "padding-left: .5em; padding-right: .2em;")
Error in prGetStyle(cell_style) :
Invalid styles detected, one or more styles lack the needed style 'name: value': 'none'
Calls: htmlTable ... withVisible -> <Anonymous> -> sprintf -> prGetStyle
Execution halted
Could you please take a look?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.