I'm wondering if you can assign id to tabs (and other elements more generally) in r flexdashboard.
I'd like to do this so I can create conditional panels based on which tab is clicked.
I have a very limited knowledge of html.
below is an example code.
---
title: "Example"
output:
flexdashboard::flex_dashboard:
theme: simplex
orientation: rows
vertical_layout: fill
social: menu
source_code: embed
runtime: shiny
---
```{r setup, include=FALSE}
options(xtable.include.rownames=F)
library(flexdashboard)
```
Column
-------------------------------------
### Chart 1
```{r}
```
Column {.tabset}
-------------------------------------
### Chart 2
```{r}
```
### Chart 3
```{r}
```
For me, it works like this:
You attribute a 'name' to your column, for example:
Column 1 or Column mycolumn
You refer this column somewhere else in the flexdashboard, with:
[This is a column](#column-1) or
[Show me the column](#column-mycolumn)
Then, by clicking on whatever is inside the "[ ]", you'll be redirected to whats referenced in the "( )".
Related
I am trying to create a static html document with RMarkdown that contains a bunch of tables and graphs. A problem I am running into right now is that the legend doesn't load correctly unless it is on the landing page. I render my graphs using the billboarder package. I added an example:
Here's a reproducible example:
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(billboarder)
library(data.table)
```
Column {.tabset}
-----------------------------------------------------------------------
### Dummy tab
### Chart A
```{r}
billboarder() %>%
bb_linechart(melt(data.table(rock, keep.rownames = TRUE)[, area := as.numeric(area)], id.vars = "rn", measure.vars = c("area", "peri")), bbaes(rn, value, variable))
```
I've been struggling with this for a while and pretty much I want see if there is a way I can have a combined output. I'm using flexdashboard to make a dashboard and I really want to have a tab feature where I can put various monthly datasets. Unfortunately when I use .tabset I can only have one chart area per column.
Here is where I am at with my dashboard.
The problem is all that empty space below. I can't add another chart area using ### because it will just add it to the tabset.
I was wondering if there was a way to make two objects output in the area (above and below) or maybe its possible to attach a graph below it?
Any insight would be greatly appreciated. I've already tried using tabBox and tabsetPabels but it doens;t work properly so I'm stuck with this format.
Desired output:
Code:
---
title: "Example Demo Dash"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
# Tab 1
```{r setup, include=FALSE}
library(readr)
library(DT)
library(dplyr)
library(rsconnect)
require(flexdashboard)
library(shiny)
library(shinydashboard)
require(plotly)
```
Column
-----------------------------------------------------------------------
### Tab 1 Graph
# Tab 2
Column {data-width=450, .tabset}
-----------------------------------------------------------------------
```{r}
cars <- datatable(head(mtcars,10),
rownames = FALSE,
options = list(
dom = 't',
paging = FALSE,
info = FALSE,
scrollY = FALSE,
sort = FALSE
)
)
iriss <- datatable(head(iris,10),
rownames = FALSE,
options = list(
dom = 't',
paging = FALSE,
info = FALSE,
scrollY = FALSE,
sort = FALSE
)
)
```
### Cars Tab 1
```{r}
cars
```
### Iris Tab 2
```{r}
iriss
```
Column {data-width=200}
-----------------------------------------------------------------------
### Tab 2 Col 2 Graph 1
### Tab 2 Col 2 Graph 1
### Tab 2 Col 2 Graph 3
### Tab 2 Col 2 Graph 3
Column {data-width=350}
-----------------------------------------------------------------------
### Col 3 graph 1
### Col 3 graph 2
# tab 3
I've created two Rmarkdown pages that are linked together. I'd like to know if there is a way to code that the links direct to a specific spot on each page.
---
title: "Page 1"
author: "--"
date: "22 9 2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
### Header
example text.
#### example plot 1.
```{r cars}
plot(cars)
```
more example text
#### example plot 2.
```{r pressure, echo=FALSE}
plot(pressure)
```
link to [Page 2](./Page-2.html)
And Page 2:
---
title: "Page 2"
author: "--"
date: "22 9 2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
### Header
example text.
#### example plot 1.
```{r cars}
plot(cars)
```
more example text
#### example plot 2.
```{r pressure, echo=FALSE}
plot(pressure)
```
[Page 1](./Page-1.html)
For example, I'd like the page 2 link to redirect straight to the second graph. Moreso, when clicking back to page 1 - is there a way for it to save the spot I was currently looking at?
Thanks.
This feature is not provided for HTML output of rmarkdown/knitr. However, you can easily implement this using javaScript (jquery):
The idea is to include a small script that saves the last scroll position in a variable (I've called it ScrPos below) in local memory and restores the scroll position when the page is (re)loaded.
header.html
<script type="text/javascript">
// check if ScrPos is available. If so, scroll to ScrPos
$(function() {
if (localStorage.ScrPos) {
$(window).scrollTop(localStorage.ScrPos);
}
});
// save last scroll position to ScrPos before page unload
$(window).on("beforeunload", function() {
var ScrPos = $(window).scrollTop();
localStorage.setItem("ScrPos", ScrPos);
});
</script>
You may include header.html in the YAML header (of both) .rmd files like this:
output:
html_document:
include:
in_header: header.html
Note that header.html needs to be in the same directory as the .Rmd.
for the linking to the second graph part it can be easily achieved by using the div id that's used for the second graph, either by explicitly assigning it or by using transforming the spaced section title to a dash separated one `example plot 2.` => id = `example-plot-2.` i.e:
New code for page 2
#### example plot 2.{#second_graph}
```{r pressure, echo=FALSE}
plot(pressure)
```
[Page 1](./Page-1.html)
and then in page one simply add the id to the link i.e:
link to [pressure graph](./Page-2.html#second_graph)
Im creating a flexdashboard which displays a table. In the last column icons are included but they are not displayed at all because of flexdashboard. That works normally in shinydashboard. Any workaround?
---
title: "Single Column (Fill)"
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
---
```{r global, include=FALSE}
library(shiny)
library(shinydashboard)
FCB<-c(5,6,4,6,8)
TWI<-c(3,5,2,3,5)
IN<-c(2,1,1,1,1)
DF1<-data.frame(FCB,TWI,IN)
FCB<-c(0,0,1,2,4)
TWI<-c(1,2,3,4,5)
IN<-c(1,3,4,5,6)
DF2<-data.frame(FCB,TWI,IN)
DF1$direction <- ifelse(
DF1$FCB < DF2$FCB,
as.character(icon("angle-up")),
as.character(icon("angle-down"))
)
```
### Chart 1
```{r}
renderTable(DF1, sanitize.text.function = function(x) x)
```
You are using Shiny content rendered to a static file.
I added runtime: shiny to the YAML header.
If you just need arrows would using simpe UTF-8 arrows like these be okay?
If you want to render HTML in a table in flexdashboard you should use a datatable from the DT package. Note that the rendering of the HTML is escaped by default. To render the HTML in your table you have to set escape = FALSE.
Here is an option:
---
title: "Single Column (Fill)"
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
runtime: shiny
---
```{r global, include=FALSE}
library(DT)
library(shiny)
library(shinydashboard)
FCB<-c(5,6,4,6,8)
TWI<-c(3,5,2,3,5)
IN<-c(2,1,1,1,1)
DF1<-data.frame(FCB,TWI,IN)
FCB<-c(0,0,1,2,4)
TWI<-c(1,2,3,4,5)
IN<-c(1,3,4,5,6)
DF2<-data.frame(FCB,TWI,IN)
DF1$direction <- ifelse(
DF1$FCB < DF2$FCB,
"<p>↑</p>",
"<p>↓</p>"
)
DF1.table <- datatable(DF1, escape = FALSE)
```
### Chart 1
```{r}
DT::renderDataTable(DF1.table)
```
I know I can include exclude r code chunks using parameters in Rmarkdown.
http://rmarkdown.rstudio.com/developer_parameterized_reports.html
However how can I exclude or include tabs based on the value of a parameter.
Where a tab is indicated as:
## Header {.tabset}
### Tab 1
content Tab 1
### Tab 2
content Tab 2
##
I'm looking for something like
## Header {.tabset}
### Tab 1
content Tab 1
ifelse(param == False) {
### Tab 2
content Tab 2
}
##
Update
I have some troubles with the answer by StatnMap. Using this code, in the first chunk the HTML after the R chunk is still shown as is the R chunk itself. I could fix this by using a separate eval = FALSE for the R chunk, but I would rather restrict myself to a single parameter in a single chunk. Thus, to only set eval = FALSE in the asis chunk.
## HEADER {.tabset .tabset-pills}
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
``` {asis, echo = TRUE, eval = FALSE}
### TEST1
```{r echo=FALSE, warning=FALSE}
library(dplyr)
summary(cars)
```
You can also embed plots, for example:
```
### TEST2
```{r, pressure, echo=FALSE}
plot(pressure)
```
You can include your markdown syntax in a asis chunk:
```{asis, echo=TRUE, eval=param}
### Tab 2
content Tab 2
```