bookdown::serve_book() after changing style.css and saving gives error

I have followed the instructions here: https://bookdown.org/yihui/bookdown/serve-the-book.html

Using the default bookdown project that Rstudio IDE creates I run:

serve_book(dir = ".", output_dir = "_book", preview = TRUE,
  in_session = TRUE, quiet = FALSE)

All goes well: the HTML output shows in the RStudio Viewer.

Then, I modify a color from black to blue in the style.css file and save the file. My understanding from reading https://bookdown.org/yihui/bookdown/serve-the-book.html is that this change should immediately be reflected in the viewer:

The server will listen to changes in the book root directory: whenever you modify any files in the book directory, serve_book() can detect the changes, recompile the Rmd files, and refresh the web browser automatically. If the modified files do not include Rmd files, it just refreshes the browser (e.g., if you only updated a certain CSS file). This means once the server is launched, all you have to do next is simply write the book and save the files. Compilation and preview will take place automatically as you save files.

However this is not what happens when I save the change, instead the following text appears in the Rstudio console:

Output created: _book/index.html
To stop the server, run servr::daemon_stop(2) or restart your R session
Serving the directory /Users/[OMITTED FOR PRIVACY]Bookdown-Material/bookdown-mve at http://127.0.0.1:4321
Error in if (config$output_dir != ".") exclude <- c(exclude, config$output_dir) : 
  argument is of length zero
Error in if (config$output_dir != ".") exclude <- c(exclude, config$output_dir) : 
  argument is of length zero
Error in if (config$output_dir != ".") exclude <- c(exclude, config$output_dir) : 
  argument is of length zero

And nothing happens to the HTML in the preview, i.e. the change is not reflected in there.

What am I doing wrong or missing?

When you change the colour and it refreshes in your browser, could you do a browser refresh that does not use the cache (Ctrl + F5 on keyboard) and see if the CSS change appears?

Yes, I have done that and nothing changes. The color change in the style.css file is not reflected.

Here are two extra pieces of information:

  1. When I change the content of index.Rmd (e.g., from # About to # About Modified) the change IS indeed automatically reflected both in the HTML that appears in the Rstudio Viewer and in the external browser.

  2. I have noticed something: after running bookdown::serve_book() a first time, the directory _book is created (so far so good) within the project directory bookdown_mve and inside this _book subdirectory there is a copy (?) of the file style.css. So, at this point there are two style.css files, one in the main project directory bookdown_mve\style.css and one in the subdirectory bookdown_mve\_book\style.css. Previously (i.e., when writing my question) I had changed the color from black to blue in the style.css file contained in the main project directory, i.e., in bookdown_mve\style.css. I have now verified that this leaves unchanged the color in the bookdown_mve\_book\style.css file. So, I wondered: is it perhaps the case that I need to change the color in bookdown_mve\_book\style.css instead of changing it in bookdown_mve\style.css? Well, I tested this supposition. The answer is that when I change the color in bookdown_mve\_book\style.css the color change is automatically reflected in the HTML file shown in RStudio Viewer (to get it to update in the external browser I need to click refresh). While I am happy that this works, I am totally lost in making sense of this situation. Why? Because the content of _book is something that one could clear without any loss of input information (based on the output of bookdown::clean_book()) so it does not make sense to me that the CSS file that I want to change is bookdown_mve\_book\style.css as it will get overwritten if and when I re-render the book.

if this is still happening, can you open an issue in bookdown ?

Thank you

This topic was automatically closed 90 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.