Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with addition of automatic section-id for headers #1407

Closed
Gutschlhofer opened this issue Jul 18, 2018 · 5 comments
Closed

Issue with addition of automatic section-id for headers #1407

Gutschlhofer opened this issue Jul 18, 2018 · 5 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@Gutschlhofer
Copy link

Gutschlhofer commented Jul 18, 2018

Something that was discussed a few years back and closed a year ago in this thread #133 seems to be a problem for me again:

When including any r-shiny-code, RMarkdown wraps a span around it, e.g.:
<span id="outc6a1e60e89362530" class="shiny-text-output shiny-bound-output">Germany</span>

RMarkdown doesn't realise this however, and assigns the ID of the header wrong, resulting in the following:

<div id="section-country-<span id=" out7f4c15190eda4fab"="" class="shiny-text-output shiny-bound-output">-df" class="section level1"&gt;
<h1>Country <span id="out7f4c15190eda4fab" class="shiny-text-output shiny-bound-output">Germany</span> df</h1>
<p>Test</p>
</div>

The output can be seen here:
output

Here is a reproducible code:

```{r, echo=FALSE}
inputPanel(
  selectInput("region", "Please select a country:",
                choices = c("Germany", "France")))

region <- reactive({input$region})
```

# Country `r region`

The exact same thing happens when I replace the region variable in the header with renderText(input$region)

Has anyone figured out a solution to the problem yet?

The workaround also discussed in #133 with manually adding an ID works (i.e. adding {#foo} at the end of the header) though.

@yihui
Copy link
Member

yihui commented Jul 18, 2018

You mentioned it was hard to format R Markdown, and that is probably because you didn't fully read the issue guide when you create a new issue: https://github.com/rstudio/rmarkdown/issues/new (and more on the four-backtick rule).

@Gutschlhofer
Copy link
Author

Okay thanks for that @yihui , I think I have now properly edited the issue post.

@stefanavey
Copy link

This is a workaround and makes the document less readable but this is an alternative approach where you don't need to manually add an ID. I often use this approach to specify section headers dynamically inside for loops. It's a bit verbose but simple to write a function to pad with newlines, etc. if you don't want to write out full cat() every time.

```{r, echo=FALSE}
inputPanel(
  selectInput("region", "Please select a country:",
                choices = c("Germany", "France")))

region <- reactive({input$region})
```

```{r,results="asis"}
cat("\n\n# Country ", region, "\n\n", sep = '')
```

@yihui yihui added this to the v1.11 milestone Aug 7, 2018
@yihui yihui added the bug an unexpected problem or unintended behavior label Aug 7, 2018
@yihui yihui closed this as completed in adb0279 Aug 7, 2018
@yihui
Copy link
Member

yihui commented Aug 7, 2018

Should be fixed now. Thanks for the report!

yihui added a commit to RLesur/rmarkdown that referenced this issue Apr 1, 2019
…e attributes of section divs (otherwise they will be restored to HTML, so the <div> will be invalid HTML)
@github-actions
Copy link

github-actions bot commented Nov 3, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants