insightsengineering / teal.reporter

Create and preview reports with Shiny modules
https://insightsengineering.github.io/teal.reporter/
Other
8 stars 9 forks source link

pdf export truncates the table if no pagination and pagination does not have entry for column widths or cpp (content per page) #258

Closed Melkiades closed 4 months ago

Melkiades commented 8 months ago

Thanks, @m7pr, for solving these issues! I was playing around with the saving functionality, and I noticed two things:

  1. If I save directly to pdf it truncates the table (default tm_t_events example): image Also zooming in before it does truncate it, I might be missing something I need to set but I could not find it in the download menu.

  2. When adding pagination the only option is lines per page which seems to work fine, while it does automatically column wrapping w/o any way to change its values.

These are very problematic for the general user but are preceding this PR. So, this is good to go, I will open a new issue regarding this.

PS: chrome editor image

btw:

Warning in rtables::export_as_pdf(x = table_reactive(), file = file, paginate = input$pagination_switch,  :
  width of page 1 exceeds the available space
ABSMMT commented 6 months ago

Is there any solution to the truncation issue ?

m7pr commented 6 months ago

I think @kartikeyakirar once managed to figure out truncating in pdf exports

kartikeyakirar commented 6 months ago

@Melkiades, can you generate a report after installing FlexTable? It seems like the output doesn't resemble a FlexTable.

kartikeyakirar commented 6 months ago

I checked it again using flextable, it appears there's an issue related to width constraints. The maximum width we're working with, based on PowerPoint slide width, is approximately 10 inches. Currently, table adjustments are made only when the width exceeds this 10-inch threshold, https://github.com/insightsengineering/teal.reporter/blob/main/R/utils.R#L178-L181.

here I have used 6 inches threshold

image
ABSMMT commented 6 months ago

Can you help me with setting the threshold using flextable? Currently I am not able to achieve what you have there. Also is there a way to disable a PDF download for certain module ?

kartikeyakirar commented 6 months ago

Currently, you can exclude the PDF option in module but not from Report Previewer tab. this can be done by specifying the output format through the rmd_output argument. refer to thevignettesvignette("simpleReporter", "teal.reporter"). image

Here's an example of how to implement this:


teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun,
 rmd_output = c(
        "html" = "html_document",
        "powerpoint" = "powerpoint_presentation", "word" = "word_document"
      ))

Can you help me with setting the threshold using flextable?

this option is not customizable through argument this needs to be fixed in internal function of teal.reproter to_flextable() I will raise PR shortly to fix it.

Melkiades commented 6 months ago

@kartikeyakirar so do we use flextable for all ouputs? I think we should revise this as we have exporters that occasionally use flextable (only for word) and are tailored for our tables (it does not clip pdfs for example)

kartikeyakirar commented 6 months ago

Flextable fixes two issues here : it facilitates the inclusion of large tables in slides and PDFs, and it addresses the issue of lengthy, reproducible code not being fully displayed in these formats, as it tends to get cut off.

However, the problem you've highlighted will still persist if we don't utilize flextable, especially in PDFs and slides. Conversely, in HTML and Word documents, content is more easily wrapped to fit within the available space.

Melkiades commented 6 months ago

Flextable fixes two issues here : it facilitates the inclusion of large tables in slides and PDFs, and it addresses the issue of lengthy, reproducible code not being fully displayed in these formats, as it tends to get cut off.

However, the problem you've highlighted will still persist if we don't utilize flextable, especially in PDFs and slides. Conversely, in HTML and Word documents, content is more easily wrapped to fit within the available space.

Mmmh, there might be a misunderstanding here. We need to be on the same page on what it is used in {teal} for exports.

Did you encounter these issues when doing rtables::export_as_pdf? It would be silly to be using some other faulty functionality when we dedicated a very large amount of time to providing pagination functionality so to paginate correctly in Txt and, hence, PDF formats.

For slides and Word, we need to use flextable, I agree, but which function do you use to transform {rtables} objects to flextable? Do you use rtables::tt_to_flextable? Ok you use teal.reporter::to_flextable. I was not aware of this double programming ahah. We need to compare the two and merge them in rtables, as it is also exported there

kartikeyakirar commented 6 months ago

Did you encounter these issues when doing rtables::export_as_pdf?

No, the function actually divides the table across multiple pages. However, I am not sure that rtables::export_as_pdf can be integrated directly with other content while rendering report (as it create single pdf file for table). I will explore adapting the logic from export_as_pdf to enable rendering of additional content alongside tables. This adjustment will also be necessary for supporting the 'data.frame' class in teal.reporter. I'll assess the feasibility of these changes.

Do you use rtables::tt_to_flextable? Ok you use teal.reporter::to_flextable. I was not aware of this double programming ahah. We need to compare the two and merge them in rtables, as it is also exported there

It seems I was previously unaware of this. I'll compare and update to_flexttable to utilizertables::tt_to_flextable, especially since to_flextable supports data.frames as well.