Skip to content
Advertisement

Dynamically load data into rmarkdown html output

Is there a way to have the data associated with and html output file generated via Rmarkdown be loaded dynamically (e.g., via javascript or ajax) when opening the html output?

For instance, I have this simple Rmarkdown file which produces a plot (in svg) and a table:

JavaScript

Is there a way to feed the data to the html file so that when the data changes and I open it again the plot and table are updated automatically without having to render the Rmarkdown script?

Advertisement

Answer

Yes, this is possible. You can use local data or data stored somewhere–like Google Sheets.

Step 1) Add runtime: shiny to your YAML. This does not make this “shiny”, but does make it dynamic.

Updated YAML:

JavaScript

Step 2) Use a function to call your data.

JavaScript

Whether in the Viewer pane in RStudio or in your browser, you only need to refresh the view or page after you update the data.

To test this the only other code I used is the following:

JavaScript

enter image description here

I changed the column name to “Displacement” and refreshed (not reran, run, knit, just refresh)

enter image description here

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement