I have mp4 file located in sharepoint and i would like to embed into html rmarkdown? how to do so?
If I read R Markdown: The Definitive Guide by *Yihui Xie, J. J. Allaire, Garrett Grolemund* correct it should work with standard image syntax !\[\](path/to/file)
Here is a link to the book: R Markdown: The Definitive Guide
If you consider Quarto, you can find the topic in the guide: Guide – Quarto
Unfortunately you can't write the v-word, so I can't post the direct links to the chapters, but both resources have searches that make the topic easy to find.
Since the file is on SharePoint, one option is to use its own embed code. In SharePoint or OneDrive, open the file, choose the Embed option (it may be under Share or the three-dot menu), and copy the iframe code it gives you. Paste that iframe line directly into your Rmd, outside any code chunk, and it will show the player in the HTML output. Embedding can be switched off by your organisation, and viewers will need access to the file, so test it in a private browser window. If that is not available, download the mp4, keep it in the same folder as the Rmd, and use the HTML5 media element that has the same name as the thing you want to embed. A plain SharePoint sharing link will not work as the source, because it opens a preview page and not the raw file.
The most reliable approach is usually to use SharePoint/OneDrive's own Embed/iframe code if it is available, and paste that directly into the Rmd outside any code chunk.
The syntax is for images, not MP4 files. For a local MP4, use raw HTML outside any chunk: and keep the file in the same folder as the Rmd. For SharePoint, use its Embed code outside chunks and check access in a private browser window. Raw HTML works only in HTML output, not Word or PDF.
Thanks for the detailed suggestions — a couple of things that helped me sort this out in my own testing:
For a SharePoint-hosted file, the Embed code is the reliable route, because a normal SharePoint link opens the preview page rather than the MP4 file itself. One thing worth checking is the access test emmamartin mentioned: open the rendered HTML in a private browser window. If it asks for a sign-in there, viewers without SharePoint access will see the same thing.
For a local file, the HTML5 media element outside a code chunk is the way to go, with the MP4 kept in the same folder as the Rmd and the rendered HTML so the relative path still resolves when you share both files together.
The image syntax will not play an MP4, so it is worth avoiding that for this case.