3

Any recommendations for rendering tables serverless with {rmarkdown}? I need to do this so I can push the rendered HTML to a Confluence page with the help of {conflr}.

When I render something like the below in an RMD file and then try to send to Confluence using conflr:::confl_create_post_from_Rmd_addin(), I get this error:

output file: serverless_test.knit.md

Error: Functions that produce HTML output found in document targeting commonmark-yaml_metadata_block output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:

  always_allow_html: true

Note however that the HTML output will not be visible in non-HTML formats.

After adding the suggested flag, the table still does not render.

If I try to run it locally without pushing to Confluence using DT:renderDT(..., server = FALSE), I get a warning This R Markdown document contains Shiny content, but was rendered to a static file. Shiny content in the document may not appear, and will not be interactive. In addition, the filter = "top" renders the text box at top of each column to filter column contents, but when you enter text nothing happens.

---
title: "serverless_dt"
author: "Matt Wood"
date: "2022-08-17"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE)
library(tidyverse)
library(DT)
```

```{r}
DT::datatable(iris) 
# %>% DT::renderDT(server = FALSE)
```

conflr:::confl_create_post_from_Rmd_addin()

Thanks for any help!

manro
  • 3,529
  • 2
  • 9
  • 22
M. Wood
  • 450
  • 4
  • 13
  • 1
    For Rmd, you can just use `DT::datatable(iris)` without code after the pipe. – lz100 Aug 17 '22 at 22:09
  • @lz100 Can you point to an example where the result does not require the server OR `Shiny` and allows for full interactivity of the datatable? – M. Wood Aug 17 '22 at 22:13
  • 1
    check the official website. The first example under Usage is the same as your question: https://rstudio.github.io/DT/ – lz100 Aug 17 '22 at 22:17
  • Updated OP to be more explicit as to what I'm trying to do. May be hard to test because it requires a Confluence subscription and a space in there which the user can edit. – M. Wood Aug 17 '22 at 22:46

1 Answers1

2

The problem is that DataTables(DT) library is a htmlwidgets thing which isn't supported by conflr.

You can use only static content with the chunk option screenshot.force = TRUE

manro
  • 3,529
  • 2
  • 9
  • 22
  • Thanks @manro, that does appear to be the problem. Do you have recommendations for a static table library that allows for background colorization in cells? I have a table with one column that needs red/yellow/green "stoplight" colors in the cells depending on their numeric value. – M. Wood Aug 18 '22 at 12:05
  • 1
    @M.Wood Maybe ```kableExtra```? https://haozhu233.github.io/kableExtra/awesome_table_in_html.html – manro Aug 18 '22 at 12:08
  • Thanks, will try it. The table just above `Insert Images into Columns` section is close to what I would like to do. – M. Wood Aug 18 '22 at 12:26
  • 1
    @M.Wood Yes. If you will have new questions - you are welcome ;-) – manro Aug 18 '22 at 12:29
  • Appears there is a bit of xml that `conflr` is choking on, even with kableExtra. Happens irrespective of `screenshot.force` setting. ```` Listening on http://127.0.0.1:7525 Warning: Error in read_xml.raw: xmlParseEntityRef: no name [68] 57: read_xml.raw 56: read_xml.character 54: translate_to_confl_macro 53: confl_upload 52: :: shiny observe 51: 8: shiny::runApp 7: shiny::runGadget 6: 4: output_format$post_processor 3: rmarkdown::render 2: confl_create_post_from_Rmd 1: conflr:::confl_create_post_from_Rmd_addin ```` – M. Wood Aug 18 '22 at 16:31
  • @M.Wood Hm, i don't know. Something again with ```conflr```. I wanted to experiment, but couldn't do it. We can't see the output in browser without access to Confluence? – manro Aug 18 '22 at 19:35
  • yeah, from the error I think `conflr` is trying to convert the HTML to some Confluence XML schema to shove through Confluence API and burps when it gets to the table because the XML converter cannot handle that object. Your earlier impulse to pass the table as an image was the right one I think. A more elegant/correct solution would be to use `httr2` or `rcurl` to pass a table using [Confluence's API](https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Create-a-table-in-Confluence-from-a-REST-API-call/ba-p/1393107). FWIW, Confluence has a free tier. IDK about API support tho – M. Wood Aug 19 '22 at 13:50
  • 1
    @M.Wood Maybe, you shouldn't lose any sleep over this problem and simply save ```kableExtra``` table as image https://haozhu233.github.io/kableExtra/save_kable_and_as_image.html and after paste it via ```knitr::include_graphics```? – manro Aug 19 '22 at 14:02
  • I tried, but pulled the following error at the call to `kableExtra::as_image()` `Error in include_graphics(temp_png, dpi = img_dpi) : Cannot find the file(s): "name_of_my_file.png"` This may be a known issue with knitr: https://stackoverflow.com/questions/60292022/knitr-cannot-find-img-files-in-static-folder – M. Wood Aug 19 '22 at 15:23
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/247389/discussion-between-manro-and-m-wood). – manro Aug 19 '22 at 15:33