bs4_book table of contents incomplete

Hello. I've come back to using RStudio, having made a website using bs4_book format some time ago. When I knit my old project file (I think its the latest one) or when I simply try to knit a new project in the bs4_format I only get the first line of the table of contents i.e. for the initial blank project the table of contents reads 'Chapter 1 About' and that's all.

I've messed around reinstalling R, updating all packages and RStudio on two different systems and both still have the same issue. Admittedly how this all works 'underneath the hood' is a bit beyond me.

Advice appreciated.
Sam

Are you able to share an example, or a link to source repo of you project ?

Without being able to have a look it is hard to help. You could try latest version of bookdown and demo template book - it should work.

Please do report in our Github issue tracker if you can find an example. Thank you

Hi, thanks for your time.


This is how the demo template book appears when I knit the demo, this is the same on three different machines.

I've updated all the the packages just using RStudio. A few version checks that seem they may be relevant:

packageVersion("bookdown")
[1] ‘0.38’

packageVersion("xml2")
[1] ‘1.3.6’

packageVersion("rmarkdown")
[1] ‘2.26’

When you start talking about the 'source repo' is where my understanding of this becomes very strained! I have the project files, however as it is the demo I'm not sure that is helpful.

Zip file

I'll consult the Github page (hopefully), it may be apparent I'm very much a novice regarding Github etc, I find the relationships between many of the aspects of using Rstudio confusing!

Cheers
Sam

An interesting development is that I just installed the servr package and tried 'bookdown::serve_book()' and the preview in the 'viewer' tab has a complete left hand table of contents as you would expect. Yet when the project is knitted the left hand table of contents only has the 'Chapter 1 About' item, as shown in the image above.

If I knit the project with a fully functional preview in the 'viewer' tab, the contents menu in the viewer tab then breaks.

This looks like it could be helpful to someone:
<simpleError in !opts$get("preview") || opts$get("input_rmd") %in% get_index_file(): 'length = 8' in coercion to 'logical(1)'>

How do you knit exactly ?

I'll try to reproduce with your zip content

The knit button which is available when the index.rmd file has focus, indicated by red arrow in the picture.

The bottom right of the image provided shows how when I use bookdown::serve_book() the preview shows the full table of contents. If I then click knit the contents table breaks and appears as shown earlier in this conversation.

Thanks again for your time.

Cheers
Sam

The knit button will only run a preview as explained in 5.4 RStudio IDE | bookdown: Authoring Books and Technical Documents with R Markdown
The build pane will have a button to build everything.

So I am wondering if this happens because you are only preview the file.

Did you try

  • Build the book once (Build pane or render_book())
  • Then preview one file (using knit button)

Is the TOC showing complete ?

See about

I wonder if this is something related to the order you run things (previewing a chapter before having build the whole book once)

Or possibly this is a limitation of bs4_book() where TOC is not being able to be computed when previewing a single chapter.

Well, embarrassingly it does seem that is the solution! I was sure I had tried to 'build book' and failed but now it is working perfectly when I 'build all' or 'build book' in bs4 format. Through the process I did upgrade a range of packages and R, but it seems my problem is solved. I also discovered Quarto Books during this process and am now wondering if my next project should use that.

Thanks for your time, I can now start to think about creating some content again.

Kind regards
Sam

1 Like

Gald I could help and it works now !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.