I am trying to create Word document using inputs into a Shiny app.
The workflow would be:
User enters data into a Shiny app
The data is written to a Rmd
The Rmd is knitted to Word
I am trying to take the input of the user to create a MS Word Chart object in the final word file. Is there a way to add code chunks in the Rmd which produce MS Word Charts. I know officeR has the capability to create Word docs with MS Word Charts, but the package requires to write the chart to an existing Word document. In my case, I want to write the MS Word Chart in the Word document which is being created from an Rmd.
@cderv Thanks for your response. I have gone through the documentations you mention in detail before and could not find any officeR or mscharts function to return a MSChart while knitting an Rmd. I have come up with the following solution but am not sure how scalable this is.
The process I followed was to
Set my YAML output as officedown::rdocx_document:
Add r code chunks where I needed the the MSCharts to be output
The code chunks would create the chart object (using mscharts::my_barchart ()),
Write the chart object to a temp word document (using officer::body_add_chart())
Inserting the chrt object back into the document (using officer::block_pour_docx())
Thoughts on this process? It seems a bit hacky; there might be a better/native way to do it using OfficeR/mscharts?
As of 2020 it seems it was not possible from this SO question:
Probably still not possible...
This seems like a good solution to me! In the R Markdown ecosystem there are a lot of post process of output (TeX, HTML, ...) so post processing your docx result using officer seems ok to me!