HTML document from rmarkdown including Shiny - section links don't work2

I'll try again:

Hello,
This is my first post! I have made an rmarkdown document like the below minimal example that uses Shiny. My problem is with the links to the sections. They work fine in RStudio, but for some reason, when the .Rmd file is put on my Shiny server and accessed from the web, the link #top works but the link #template does not. (Links below commented out because of rule "new users can only use 2 links.)

---
title: "Step by step normal app"
author: "Dan"
date: "March 1, 2018"
output: html_document
runtime: shiny
---
Stuff above the introduction.

## Introduction {`#top`}

## The Template {`#template`}

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

t

This should make a [link to the top of the page](`#top`).

This should make a [link to the template](`#template`).
1 Like

My apologies, let me try to clean this up:

I have made an rmarkdown document like the below minimal example that uses Shiny. My problem is with the links to the sections. They work fine in RStudio, but for some reason, when the .Rmd file is put on my Shiny server and accessed from the web, the link #top works but the link #template does not.

Any help would be greatly appreciated. Here is the code from R markdown:

---
title: "Step by step normal app"
author: "Dan"
date: "March 1, 2018"
output: html_document
runtime: shiny
---
Stuff above the introduction.

## Introduction {`#top`}

## The Template {`#template`}

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
[Make a lot of vertical space so you can see the effect of the links]

This should make a [link to the top of the page](#top).

This should make a [link to the template](#template).

Thanks again!

The bottom code should say

This should make a [link to the top of the page](#top).

This should make a [link to the template](#template).

Hi @dadrian14, congrats on your first post! :blush:

This works for me:

## Introduction

## The Template

This should make a [link to the top of the page](#top).

This should make a [link to the template](#the-template). 

If I remember correctly, the link text has to be all lowercase and the spaces should be replaced by dashes.. Hopefully, it works for you too! :blush:

Also, for future reference, you can edit you posts by clicking the pencil icon at the bottom of your posts ^^

Hi @dadrian14,

Per our community guidelines, we ask that you please refrain from cross-posting on the categories.

https://forum.posit.co/guidelines#keep-tidy

Since it looks like you're getting help over here, I'm gonna go ahead and close out the other thread you opened in the Shiny category.

https://forum.posit.co/t/html-document-from-rmarkdown-including-shiny-section-links-dont-work/5719

Thanks

2 Likes

Thanks, but unfortunately it still isn't working for me. I click on the section link (for example, #top), and the URL says STUFF/#top but the document doesn't go to the Introduction. Interestingly, if I manually change the URL to be STUFF/#section-top it works.

Hi, I'm really sorry, but I made some mistakes last time: I stupidly didn't copy the YAML ^^" (I think it made a difference because you had runtime: shiny) and one of the links didn't actually work, I just thought it did because (#top) links to the top of the document.

Does this maybe work for you?

## Introduction

## The Template

This should make a [link to the top of the page](#top).

This should make a [link to the introduction](#section-introduction).

This should make a [link to the template](#section-the-template).
1 Like

This works! Thank you! I guess I was missing the #section- part.

The links don't work in the RMarkdown previewer though. Do you know of a fix for that?

1 Like

strange, it works for me.. maybe we're using different versions of something?

packageVersion("rmarkdown")
[1] '1.8.10'
packageVersion("shiny")
[1] '1.0.5'

R version 3.4.1 (2017-06-30)
RStudio Version 1.1.423 (on a Mac)

Hi @dadrian14, would you mind marking this post:

as the solution? It'll help others who have the same problem as you did (the topic will be marked as solved and a preview of the solution will appear directly below your question :blush:)


You can find more information here:

Thanks!