You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RMarkdown:site.yml指定prettydoc输出主题后导航栏消失求助

Fixing Navbar Not Showing When Using prettydoc::html_pretty in site.yml

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:

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:

  1. Create a file named navbar.html in 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>
  1. Update your site.yml to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:51:22