Search code examples
rshinyflextable

Isolating saved PNG files between sessions in a Shiny app


I do not know how to illustrate this with a simple example. The problem is this:

I generate and display a flextable in a Shiny app and want to place it in a PDF. The only available method is to convert the flextable object to a PNG then place the PNG in the PDF. This works fine, except users are reporting strange results - getting the report with a table that looks nothing like that displayed in the app. I suspect that occasionally users are executing reports very close in time so that the last saved png is grabbed, but it was saved by another user.

The PNG files (there are three) are placed in the app directory, which I believe is not isolated from one user session to another. In the PDF I cannot use relative paths so I cannot save it to a different directory.

Any suggestions?


Solution

  • Have you tried naming the images with a unique key, such as a per-report number getting the images named something like chart_0153927_01.png instead of chart_01.png for report #0153927? Or something like a millisecond/microsecond timestamp set once at the start of the session to reduce collisions?