-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datatables generated in a loop in .Rmd file? #67
Comments
I have the same problem. Couldn't find a solution so far. :( |
@ldecicco-USGS @kkrismer For some reason you can only generate one datatable per chunk. To workaround that limitation you should dynamically create one chunk per datable that you want to display. Dynamically creating rmarkdown chunks was solved on stackoverflow (http://stackoverflow.com/questions/21729415/generate-dynamic-r-markdown-blocks). Here is a gist that I think achieves your desired result: https://gist.github.com/ReportMort/9ccb544a337fd1778179 To test the datatable functionality for searching, pagelength, paging, etc still works I created another gist that splits the iris dataset into 3 parts (one for each species). The code generates 3 chunks to display a datatable for each part of the data set. Those datatable options seem to work fine, so I think this solution will work. |
Thanks for the solution. That is certainly one way to go. I have another solution proposed at ramnathv/htmlwidgets#110 I'll let you know once the proposal is accepted. |
My work around. Haven't tested with datatable but works with another htmlWidget, DiagrammeR. Say you have a data frame called
|
Turns out that the solution is fairly simple -- just use
|
@yihui that works, but only in the simple case of printing several
Output looks like this. If you check the source HTML and intermediary Markdown, you can see the HTML for the |
Instead of |
Unfortunately this workaround does not seem to work when e.g. creating an ioslide presentation. |
Can you be sure that you have set the ```{r, results='asis'}
# your code
``` |
Hm. I thought the following should work as part of an ioslide presentation (minimum example): ---
title: "aaa"
author: "aaaaa"
date: "2018/10/2"
output: html_document
---
# Test
```{r test}
library("htmltools")
library("DT")
createDT <- function(variable){
return(list(tags$h2(names(cars[variable])), datatable(cars[variable])))
}
htmltools::tagList(lapply(as.list(1:2), function(x) createDT(x)))
``` Spoiler: it does not work I tried a lot of things, including a combination of |
It certainly works for regular markdown documents. However, it does not work for ioslide presentations as stated above. Switching to the next slide is not happening by using |
@RomanBi This certainly works for you. ---
title: "loop DT in ioslides"
author: "shrektan"
date: "2018/10/2"
output: ioslides_presentation
---
# Test
```{r, echo=FALSE,include = FALSE}
# You need this code to conduct the magic dependences attaching...
DT::datatable(matrix())
```
```{r test, results='asis', echo = FALSE}
for (i in 1:3) {
nm <- colnames(iris)[i]
cat(sprintf("\n\n## %s\n\n", nm))
cat("\n\n")
cat(knitr::knit_print(DT::datatable(iris, width = "100%")))
cat("\n\n")
}
``` |
Thank you very much, @shrektan! Works like a charm. How could I miss that? ;) |
@shrektan 's solution worked perfectly. For all of 5 minutes. Since then all I did was install Any ideas anyone? |
A minimal example will help... |
Just the exact code from above. It leads to knit_print() calling
webshot::webshot(). Before installing plotly it simply printed the
datatable into the knitted htm.
Am Do., 17. Jan. 2019, 16:00 hat Xianying Tan <notifications@github.com>
geschrieben:
… A minimal example will help...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#67 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AmjZSzvFltmp3Ta2IFoH3upajzyp_-FLks5vEJABgaJpZM4ERnBP>
.
|
It works on my computer after plotly being installed. |
The workaround In the case of a datatable smaller than 10 lines, it includes a lot of blank space after the table. Any solutions to avoid this ? Thanks in advance ! EDIT: Solved adding height = "100%", width = "100%" parameters to datatable() example: |
Thank you @shrektan, that was the missing part for me,. |
I'm trying to generate a set of datatables from a loop within an rmarkdown file. Something like:
While the straight R produces 2 tables, no tables show up in the 'Knit' html document.
So, this works for 1 table:
But I can't loop through and make several tables. Is there a
print
-like function I'm missing? Thanks for the awesome package!The text was updated successfully, but these errors were encountered: