Internal section anchors not working in urls when publishing to Rpubs

Using knitr/rmarkdown I'm creating a document with sections. When viewed in the browser I can successfully navigate to a section (let's call it Section Name) by adding #section-name to the end of the url.

But after publishing the document on Rpubs, adding #section-nameto the end of the url for the published document no longer works. I've tried also specifying the anchor directly with html: <a id="section"></a> and adding #section` to the end of the url, but that doesn't work either.

I know there are some finicky issues with urls in Rpubs (see

Is this a known issue? Is there a workaround?


This unfortunately happens because when viewing a document on, you're actually viewing a wrapper page, within which the actual document is embedded, via an iframe. So the #section-name in the browser URL bar applies to the wrapper page, not the actual document. I can't think of a way around this, other than creating a link directly to the underlying document. There are a couple of annoyances with this workaround: 1) the URL will be long and ugly, e.g., and 2) it is a bit cumbersome to figure out the URL.

If you'd like to go this route though, you can do so by invoking your browser's View Source command (Command-Option-U on Chrome for Mac, for example) and finding "iframe" in that page--you should be able to click on the URL in that tag.

1 Like

Many thanks @jcheng . Not what I'd hoped to hear, but it's good to have an answer.

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.