How to incorporate html table in Rmarkdown - html

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.

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
---

Rmarkdown (html): local search for table of contents (toc)

I was wondering if Rmarkdown for html outputs has a function that can do a local search for the TOC only. I don't want to use the Ctrl+F function as I have got repeated words used as the section names and it would be much slower than just searching over the TOC.
The TOC is built using Tocify.js. It does not have any such feature, so don't expect anything in RMarkdown unless you cook one up using JQuery/Javascript.

Adding URL links in table charts

We have a Superset table that displays data based on an SQL query. Currently, all the data is rendered in HTML div/span tags.
We need to open a link in a new tab on click of one of the columns. If we send the raw link in anchor tag, it displays <a href={{link}}></a>, because the superset code wraps all the contents in a div/span tag.
Is there any way this can be done?
As far as superset use df.to_html to render the pandas data frames to Html on Dahsoborads Explore Tabs, you can use HTML tags and other on your queries. For example, I developed this simple query that generates a simple table of charts with CSV download links. Check This out:
Write The query like this:
Try to explore it(click on the explore button!):
As far as I know, you can't. All visualization on superset is based on d3. You might want to look for custom visualizations on their site.

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}

How to create a PDF in reStructuredText?

The documentation for the uncertainties Python package is written in reStructuredText, for the Sphinx documentation system. The HTML looks fine. I would like to create a PDF version. The goal is to have a "chapter" for each of the web page.
However, what happens is that the PDF generated by the ReST files transforms the (HTML) sections of index.html into individual chapters (which I don't want: the PDF should have them as sections too). Another problem is that all HTML pages after the main page appear in the PDF as subsections of the section where the toctree directive appears (i.e., in the Acknowledgment section of the main page).
So, how should the ReST file be structured so that (1) the web documents look the same as they are now, and (2) each web page corresponds to a PDF chapter. Any help would be much appreciated!
There is a solution. If I remember correctly, the key points were:
Use a special Table of Contents as the master document (I used index_TOC.rst instead of the default index.rst): in conf.py
master_doc = 'index_TOC'
latex_documents = [('index_TOC', 'uncertaintiesPythonpackage.tex',…]
The new Table of Contents file index_TOC.rst contains a ToC like
TOC
===
.. toctree::
:hidden:
:maxdepth: 1
index
user_guide
numpy_guide
tech_guide
Thus, the web version still opens onto the main index.rst text, and the PDF (LaTeX) version has each ReST file in a separate chapter.