formattable

How do I get kable and formattable to work together when creating a table in R?

折月煮酒 提交于 2021-02-11 14:32:26
问题 Both kableExtra and formattable have fantastic features and I'll like to be able to incorporate them both in my tables. Here is the table formatted using formattable: Health_status = c("Very good", "Good", "Fair", "Bad", "Very bad", "Not stated", "Total") Number = c(1032169, 453975, 125502, 22095, 5019, 73528, 1712288) Percent = c(60.3, 26.5, 7.3, 1.3, 0.3, 4.3, 100) Change = c(37672, 15231, 6536, 1988, 525, 30315, 92267) Percent_Change = c(3.8, 3.5, 5.5, 9.9, 11.7, 70.2, 5.7) df <- data

Adding logos/images to the side of a data table

十年热恋 提交于 2021-02-10 06:26:49
问题 I have searched for a way to create a table with logos/images as a column of a data table. I've attached an image of the sort of table I'd like. The data table was taken from an example using library(formattable) , and I pasted in logos on top of the 'id' column to show the sort of design I'm looking for. Ideally this would be neater and customizable (perhaps the entire table background in black with white/grey writing etc. Does anyone have any examples they can share? Code to create

RMarkdown formattable tables within do.call() and apply() appearing in wrong order

China☆狼群 提交于 2021-02-08 04:28:25
问题 I'd like to print a series of texts and formattable tables (i.e. the formattable package) in RMarkdown. I would want the output to appear as: text 1 formattable table 1 text 2 formattable table 2 text 3 formattable table 3 Since formattable tables don't appear when using a for loop, I'm using the RMarkdown formattable example loop, which uses a wrapper function, do.call() and lapply() instead of a for loop. Here's a slimmed-down version of that example that demonstrates the issue I'm having:

Combining color_bar(…) and percent(…) in R formattable

对着背影说爱祢 提交于 2020-08-27 08:32:10
问题 I'm trying to create a color_bar where the bars are based on the percentage of a subset of row values i.e. a1=(a1+b1)/2. However, I also want the numbers to be formatted as percent. I have tried googling but can't find anyone else having a similar problem. I suspect there might be a better way of doing this that is easier but I can't figure it out. tempDf = data.frame(a=c(0.8,0.5), b=c(0.2,0.5),c=c(500,500)) # dummy data formattable(tempDf,unlist(list( lapply(as.list(1:nrow(tempDf)), function

printing blanks instead of NA's when using formattable in R

自闭症网瘾萝莉.ら 提交于 2020-06-10 03:40:42
问题 Consider the example data.frame df <- data.frame( id = 1:4, name = c("Bob", "Ashley", "James", "David"), age = c(48, NA, 40, 28), test1_score = c(18.9, 19.5, NA, 12.9), stringsAsFactors = FALSE) I'm using the R package formattable to make a pretty table. library(formattable) formattable(df, list( age = color_tile("white", "orange"), test1_score = color_bar("pink", 'proportion', 0.2) )) It used to be that NA's were automatically not printed, and a blank was printed instead. It seems like this

Loop, hide columns and r formattable

余生长醉 提交于 2020-02-05 09:24:57
问题 I have this A<-1:10 B<-10:1 C<-11:20 df<-data.frame(id=1:10,A,B,C,tA=A>5,tB=B>5) I'm using formattable and this is what I would like to have (Output 1) formattable(df, list( id = formatter("span", style = ~ style(color = "gray")), A=formatter("span", style = ~ style(color = ifelse(tA==TRUE, "green", "red")), ~ icontext(ifelse(tA==TRUE, "arrow-up", "arrow-down"), A)), B=formatter("span", style = ~ style(color = ifelse(tB==TRUE, "green", "red")), ~ icontext(ifelse(tB==TRUE, "arrow-up", "arrow

Loop, hide columns and r formattable

妖精的绣舞 提交于 2020-02-05 09:22:27
问题 I have this A<-1:10 B<-10:1 C<-11:20 df<-data.frame(id=1:10,A,B,C,tA=A>5,tB=B>5) I'm using formattable and this is what I would like to have (Output 1) formattable(df, list( id = formatter("span", style = ~ style(color = "gray")), A=formatter("span", style = ~ style(color = ifelse(tA==TRUE, "green", "red")), ~ icontext(ifelse(tA==TRUE, "arrow-up", "arrow-down"), A)), B=formatter("span", style = ~ style(color = ifelse(tB==TRUE, "green", "red")), ~ icontext(ifelse(tB==TRUE, "arrow-up", "arrow

R datatable buttons export with formated cells

大兔子大兔子 提交于 2020-01-11 10:32:25
问题 The extensions Buttons works great for shiny application, from library(DT) . However it export the data without formatting. Is there a way to export data with format (e.g. percentage, or currency)? Similar question left unsolved. Reproducible code library(DT) data.frame(a = c(1,2), b = c(2,3)) %>% datatable(extensions = 'Buttons', options = list( dom = 'Bfrtip', buttons = c('copy', 'csv', 'excel', 'pdf', 'print')) )%>% formatPercentage('a') %>% formatCurrency('b') 回答1: Instead of using the

Is it possible to use more than 2 colors in the color_tile function?

荒凉一梦 提交于 2020-01-11 10:22:16
问题 I have a dataframe column that I'm currently formatting using the formattable::color_tile function (below): color_tile( "red", "springgreen" ) My issue with this is that the values near the middle are an ugly brown color, and I'd ideally like it to be a red-amber-green gradient, but color_tile seems to only be able to take min.color and max.color parameters - is it possible to use a 3rd color with either this or similar formatting functions in R? 回答1: It doesn't look like the function is

Is it possible to use more than 2 colors in the color_tile function?

梦想与她 提交于 2020-01-11 10:21:49
问题 I have a dataframe column that I'm currently formatting using the formattable::color_tile function (below): color_tile( "red", "springgreen" ) My issue with this is that the values near the middle are an ugly brown color, and I'd ideally like it to be a red-amber-green gradient, but color_tile seems to only be able to take min.color and max.color parameters - is it possible to use a 3rd color with either this or similar formatting functions in R? 回答1: It doesn't look like the function is