Markdown HTML output - html

I am doing the knitting of my code to produce a html file. I got it but next to the graphs it also display some boxes with information about i.e. line, color, text and so on. Is it possible not to see that information in my html file?

add echo=FALSE to the r chunk. It will remove the evaluated code inside the chunk. Also you can add message=FALSE, and warning=FALSE to not show messages and warnings.
Example (It will plot the chart and not show the code, warnings and messages).
```{r, echo=FALSE,warning=FALSE,message=FALSE}
plot(iris)
```

Related

Show output but hide code when sending Rmd to other people?

I have a problem with Rmarkdown when teaching. How can I send file .Rmd to other people without code but output remains?
In python (jupyter notebook, gg collab), I write code and run. After that, I delete the code and send the notebook to other people. They can't see code, but they know the output. Their mission is to write code to have the results as mine.
Is there any platform in R for designing exercises (hide code but show output)?
Thank you for all your advice.
There are a few things you can do with Rstudio and Rmarkdown, I will be creating HTML documents using Rmarkdown and Rstudio.
First, you can specify each R chunk to hide the code, this can be done with some chunk options, or easily clicking the preferred option. This is where you can see there is an option to "show output only", no matter the code inside the R chunk.
Second, you can use the below YAML settings that allow you to render a single HTML document, and allow the end user to select if they want to see the R chunk code, or hide it, while still showing the output.
---
title: "Untitled"
author: "author"
date: "9/25/2021"
output:
html_document:
code_folding: hide
---

Convert markdown table of contents to HTML

I am trying to convert a markdown document to HTML, using pandoc. I cannot get the HTML output to create the table of contents correctly.
Issue:
I have added a table of contents to the markdown doc, where clicking on each header takes the reader to the relevant section. I am using the format below, where clicking on 'Header Title' will send the reader to the section 'header' in the document:
[Header Title](#header)
I tried to convert this to HTML using the pandoc command
pandoc -i input.md -f markdown -t html -o input.html
This creates a valid HTML file I can open in Firefox, and the items in the table of contents show up as links - but when I click them, nothing happens (I am expecting it to jump to the relevant section)
This happens when I use either markdown or markdown_github as the input format (-i in pandoc)
Question:
How can I get the table of contents to show the expected behavior in HTML?
Or is the concept of 'table of contents' a wrong approach to HTML, and I should change my markdown code?
Apologies if I am going about this the wrong way, I have no experience with HTML / web documents.
I found a couple of similar questions but they seemed to be specific to other programming languages / tools, so any help how I can achieve this with markdown / pandoc is much appreciated.
I am using pandoc 1.19.2.4 on Ubuntu.
Example markdown:
- [Chapter 1](#chapter-1)
- [1. Reading a text file](#1-reading-a-text-file)
## Chapter 1
This post focuses on standard text processing tasks such as reading files and processing text.
### 1. Reading a text file
Reading a file.
Looking at your markdown file, you have used #1-reading-a-text-file as the id for the 1st subheading.
While converting it to HTML, the following line is generated for the subheading:
<h3 id="reading-a-text-file">1. Reading a text file</h3>
The problem is the mismatch of "#1" which is present in the table of contents, but not in the heading.
My guess is that pandoc does not allow HTML id to start with a number.
Changing the table of contents to the following should work:
- [Chapter 1](#chapter-1)
- [1. Reading a text file](#reading-a-text-file)

How to get links output in a printer-friendly fashion, e.g. as numbered-citation style incuding a list of links at the end?

pandoc turns input such as
See [that site](http://my.link)
into
See that site
which means the link information will get lost in printing. I would like to get some printer-friendly version, i.e. the links numbered
See [1]
(code See [[1]](http://my.link "that site")
and at the end (or optionally as a footnote when using xelatex to get a pdf) a summary of all links, i.e.
[1] that site: http://my.link
(whether the original link title shall be in this list or not is optional).
How can this be achieved? Via a filter or is there already some switch for that?
You can use footnotes:
Here is a footnote reference[^1]
[^1]: Here is the [footnote](http://my.link)
which will also result in footnotes in HTML output. For more flexibility, see this answer, e.g. this will only work for LaTeX/PDF output:
pandoc -o myfile.pdf -V links-as-notes=true myfile.md
Edit: this works only if you have the following in your template (from the default-template):
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$

How to incorporate html table in Rmarkdown

I used package 'sjPlot' to run some data analyses. For instant, function 'sjt.df' gives me a html table regarding simple description of variables. Then I created a Rmarkdown (see below). But when I clicked knit HTML/pdf, the result of the html table did not incorporate into the Rmarkdown. Rather, it popped up in my browser. How can I deal with that?
{r}
library(sjPlot)
data(iris)
sjt.df(iris)
See my tutorial basics of sjt-functions, section Knitr integration of HTML tables.
If you just want to have the table, use 'r sjt.df(iris, no.output=TRUE)$knitr' - (note that the ' have to be `).
The no.output=TRUE ensures that the table is not displayed in the viewer pane or browser, and the $knitr parameter contains the HTML-snippet that will be incorporated in RMarkdown.
If you also want to display the R-code, use
```{r eval=FALSE}
sjt.df(iris)
```
However, I guess that these tables are not converted well to PDF, only to HTML.

Making nicely formatted tables in Markdown: knitr not compiling stargazer>html table

I'm trying to embed an output table, nicely formatted by the stargazer function, in a markdown document.
I tried embedding the stargazer() in an R code block in the Rmd document:
```{r}
library(stargazer)
stargazer(cor(attitude), type="html")
```
The code runs correctly, but it outputs the html code that in turn is not parsed by knitr, so the actual table html 'source' code is shown in the rendered document.
I'm aware of this similar question (here). I'm asking a separate question because most answers there indicate that stargazer does not support html output, which is no longer true. Html support was probably incorporated into stargazer after that tread (and I donĀ“t have engouth rep to reopen or post comments there).
This seems related to a more simple problem of making knitr compile the html table source code.
EDIT: #hrbrmstr gave me the answer in the comment bellow, which is:
```{r results='asis'}
library(stargazer)
stargazer(cor(attitude), type="html")
```
Remove the ' from 'asis'
ex: {r results=asis}