Finished and published on github my first website using Distill package in RStudio:
https://crlnp.github.io/3-objets.html
On this particular page I include several images in my rmarkdown document and it causes problems with the table of contents: the headings are duplicated and don't follow the headings adequatly. I have tried every toc_float: option available and it does not solve the problem. Aldo tried changing the heading levels (all #, ...). The problem appears wether the image is inserted traditionally or in a code bloc. If I take out the images in my file, the TOC works perfectly. I have not been able to find any information on this issue. Thanks in advance for any help!
Your .Rmd file on the website (GitHub) repo.
If you include JS file (optional) and move wrapping div container, from current position to above your first header, TOC behaviour will change:
<script src="hideOutput.js"></script>
<div class="fold o">
## 1. Les objets
.
.
.
</div>
Is this helpful in any way?
Output:
Related
I have a r-markdown doc that has a flextable that spreads over multiple pages and on my own computer it knits to docx. perfectly. However, now it is on the server and it automated the knitted document has the table on a new page. This can be manually changed in the outputted word doc by changing "text wrapping" to "Around" in "table Properties" menu. This is workable but as these docs are automated, I would like the format to be correct from the begininng. Any ideas on how to force the table to stay on the first page with the headings??
** I should add that saving the table properties in the reference doc does not seem to help.
Cheers
Silas
I asked the author of the flextable package a similar question. He suggested I change the knitr chunk option ft.keepnext to FALSE and it worked for me.
```{r, ft.keepnext = FALSE}
myflextable
```
I have a rmarkdown script that generates html of some maps and tables. Sometimes, one of the tables is shorter than usual and the next header shifts upward into the space of the previous section. Here is an example of what is happening:
Missing Page-Break Example
I am trying to get the header of the next section to be below both the "LOB" and "Location" tables. Is there a simple way (using css, html, rmarkdown, etc) to get around this without having to create a custom page breaker that measures the number of rows of the previous table?
In Rmarkdown, i usually use <br> </br> syntax for small breaks in HTML code, according to the R Markdown Cookbook for breaks you use \newpage, but that only worked for me for PDF output
---
title: Breaking pages
output: pdf_document
---
# The first section
\newpage
# The second section
My problem is with use of relative links and "compiling" (knitting).
I'm writing a book using RMarkdown. Since the file will be relatively large, I need to split into subfiles and directories.
I have a masterfile which only includes links to chapters(chap1, chap2, ...). There is a file for each chapter and each needs references to some figures (fig1,...).
I would like to be able to knit masterfile.Rmd and chap1.Rmd independently from each others so to get one file for chapters, and one file for the whole book.
Here is how my files are organized (MVE). Directories are displayed in upper case.
ROOT
masterfile.Rmd
FIGURES
fig1.pdf
fig2.pdf
CHAPTERS
chap1.Rmd
chap2.Rmd
...
The code of masterfile.Rmd is as follows:
{r child = '/chapters/chap1.Rmd'}
The code of chap1.Rmd is as follows:
![](../figures/fig1.pdf)
As I knit from chap1.Rmd, everything is fine. As I knit from masterfile, I get the following message:
[WARNING] Could not fetch resource '../figures/fig1.pdf': PandocResourceNotFound "../figures/fig1.pdf"
It seems that fig1.pdf cannot be found. I guess that this is because the include statement in master file only "copies" the code of chap1.Rmd and "executes" it in the ROOT directory (not in the CHAPTERS directory) so ".." drives to location that does not exist (before ROOT) when knitted from masterfile.
I could change the setting and write ![](/figures/fig1.pdf) in chap1.Rmd file. It would work fine when knitting from masterfile but no longer from chap1.Rmd.
Do you know how to have both?
Welcome to the RMarkdown community!
Due to KnitR, Rmd, and pandoc inter-workings, this is not as easy of a solution as you'd think, but a directory restructure would almost be easier.
Even if you look at Rmarkdown author's newest book RMarkdown CookbookHERE. They have all the chapters in the ROOT directory, and only sub directories for images(and possibly figures).
resources:
1. Other SO similar question
2. Github options knitr question
3. similar question from Rstudio community
You can make use of the Lua filter feature to rewrite image paths when knitting the main file. E.g.
function Image (img)
img.src = img.src:gsub('^%.%./', './')
return img
end
This will replace a path like ../figures/fig1.pdf with ./figures/fig1.pdf.
Use the code writing it to a file and calling adding it via pandoc_args (in the main file only).
---
output:
html_document:
pandoc_args: ["--lua-filter=filter.lua"]
---
I built a blogdown site using Hugo and it has multiple sections, posts all written in Rmarkdown with outputs designed as html_document. It works fine.
In parallel, I designed an HTML dashboard using Rmarkdown with an output designed as flex_dashboard. It generates an HTML file working fine.
I wanted to integrate the dashboard directly within the building of the site but unfortunately by simply adding the Rmarkdown file in the blogdown structure it knits it as an html document and not as a flex_dashboard. So, I have the content within my website but not at all as dashboard but more like a traditional html_document. So no luck with that :(
I tried then copying the dashboard html under /static/html and create a brand new Rmarkdown just invoking my html within an iframe:
---
output: html_document
---
<link rel="preload" href="/html/OpenDashboard.html" as="document">
<iframe width="100%" height="600" name="iframe" src="/html/OpenDashboard.html"></iframe>
Looked good to me and was pretty happy even in inelegant but performance is bad. It takes a long time to load (+10sec) even if the file is not that big (only 6Mb). Size of the html will grow a lot in the future and I can't hope viewers will wait that long.
I read it was possible to clarify the type of knitting we want within a build.R file but I am clueless on how to specify I want html_document knitting for some Rmarkdowns and flex_dashboard for some others.
To answer your last question: in Section 2.7 of the blogdown book, it mentions that you could use blogdown::build_dir() in R/build.R to build arbitrary Rmd files under the static/ directory.
Is there an easy way to link to a webpage in rmarkdown without displaying the link?
For example, putting "https://www.google.com/" in a .rmd file renders as the entire website, but I want something analogous to ABC instead.
The html method above, i.e., <a href= ... works when I knit to html, but it does not work when I knit to a word document.
Markdown provides two ways to create a link as you mention (and I suppose that is supported on rmarkdown).
Markdown way:
[ABC](http://example.com)
HTML way:
ABC
The first way is native and the second way is supported since Markdown allows every HTML code.