Skip to content
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

Button Rendering DT in loops #867

Closed
3 tasks done
AndrewSkelton opened this issue Oct 19, 2020 · 3 comments
Closed
3 tasks done

Button Rendering DT in loops #867

AndrewSkelton opened this issue Oct 19, 2020 · 3 comments
Labels
Milestone

Comments

@AndrewSkelton
Copy link

AndrewSkelton commented Oct 19, 2020

This looks to be a bug from my perspective, or maybe not a complete workaround... When rendering DTs in a loop, the buttons expected don't appear to render. Any advice on the approach? Solution implemented from #67

---
title: "Test"
date: "`r format(Sys.time(), '%B %d %Y')`"
output: 
   html_document:
      fig_height: 6
      fig_width: 10
      keep_md: yes
      number_sections: no
      self_contained: yes
      theme: cerulean
      toc: yes
      toc_float: yes
---

```{r set_env, echo=FALSE,include = FALSE}
##
## Load Libraries
##
library(tidyverse)
library(knitr)
##


##
## Knitr Options
##
opts_chunk$set(
   include=TRUE,warning=FALSE, echo=FALSE, 
   message=FALSE,concordance=TRUE,cache=FALSE
)
DT::datatable(matrix())
##
```

# Table Printing Test {.tabset .tabset-pills}
test to see if this works

```{r tables, results='asis'}
##
## Print Tables
##
for(i in 1:5) {
   cat(paste0('## table_',i,' \n'))
   cat(knitr::knit_print({
      mtcars[,c(1:4)] %>%
      DT::datatable(rownames=F, extensions="Buttons", 
                options = list(
                       dom = "Bfrtip", 
                       buttons = list("copy",list(
                          extend  = 'collection',
                          buttons = c('csv', 'excel', 'pdf'),
                          text    = 'Download'
                       ))
                    ))
   }))
   cat('\n \n')
}
##
```
> xfun::session_info('DT')
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS, RStudio 1.3.1056

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
  LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  base64enc_0.1.3   BH_1.72.0.3       crosstalk_1.1.0.1 digest_0.6.25     DT_0.15           graphics_4.0.2    grDevices_4.0.2   htmltools_0.5.0   htmlwidgets_1.5.1
  jsonlite_1.7.0    later_1.1.0.1     lazyeval_0.2.2    magrittr_1.5      methods_4.0.2     promises_1.1.1    R6_2.4.1          Rcpp_1.0.5        rlang_0.4.7      
  stats_4.0.2       utils_4.0.2       yaml_2.2.1       

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('DT'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/DT').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@shrektan
Copy link
Collaborator

I think there should be a better & direct way for this but I don't have time to investigate at the present.

The simple solution is to replace this line:

DT::datatable(matrix())

with below (extensions and plugins needs additional resources):

DT::datatable(
  matrix(), extensions="Buttons"
)

@shrektan shrektan added this to the v0.17 milestone Oct 23, 2020
@aliazander
Copy link

@AndrewSkelton did you ever find a working solution for this? I am still not seeing the buttons in the html output.

@shrektan
Copy link
Collaborator

As I've answered above, put the following code in advance should resolve your issue.

DT::datatable(
  matrix(), extensions="Buttons"
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants