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.
This unfortunately happens because when viewing a document on rpubs.com, 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. https://rstudio-pubs-static.s3.amazonaws.com/299984_fd270fd151344f7dbf406b76e001236b.html, 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.