RMarkdown:site.yml指定prettydoc输出主题后导航栏消失求助
I’ve run into this exact issue before—when you set prettydoc::html_pretty as the global output format in your site.yml, the navbar stops rendering because the prettydoc template doesn’t integrate with R Markdown’s site navbar system. Here are two reliable fixes to get both the prettydoc theme and your working navbar:
Option 1: Use html_document with Prettydoc’s Theme CSS (Recommended)
This approach lets you keep R Markdown’s native navbar support while borrowing prettydoc’s styling. Update your site.yml output section like this:
name: "casualties" output_dir: "injuries" navbar: left: - text: "Casualties" href: index.html - text: "Casualty map" href: casualtymap.html - text: "Frequently asked questions" href: faqs.html output: html_document: theme: null # Disable default Bootstrap theme highlight: github css: !expr prettydoc:::theme_css("cayman") # Load prettydoc's Cayman theme
Why this works:
html_document is R Markdown’s core output format, so it fully recognizes and renders the navbar from your site.yml. By setting theme: null, we turn off the default Bootstrap theme, then use prettydoc:::theme_css() to pull in the exact Cayman theme styles you want. Your navbar will work as expected, and your pages will have the clean prettydoc look.
Option 2: Manually Add a Navbar via Includes
If you prefer to stick strictly with prettydoc::html_pretty, you can create a custom navbar HTML file and include it in every page:
- Create a file named
navbar.htmlin your project root with your navigation code (adjust styling to match the Cayman theme if needed):
<div class="navbar" style="padding: 1rem 0; border-bottom: 1px solid #eee; margin-bottom: 2rem;"> <a href="index.html" style="margin-right: 2rem; text-decoration: none; color: #2c3e50;">Casualties</a> <a href="casualtymap.html" style="margin-right: 2rem; text-decoration: none; color: #2c3e50;">Casualty map</a> <a href="faqs.html" style="text-decoration: none; color: #2c3e50;">Frequently asked questions</a> </div>
- Update your
site.ymlto include this file in the header of every page:
name: "casualties" output_dir: "injuries" output: prettydoc::html_pretty: theme: cayman highlight: github includes: in_header: navbar.html
Note:
You may need to tweak the CSS in navbar.html to perfectly match the Cayman theme’s typography and spacing. This method gives you full control but requires more manual styling work compared to the first option.
内容的提问来源于stack exchange,提问作者user3387656

