bsplus::bs_modal() creates a modal dialog popup, and works within a column, but not a sidebar.
Any ideas on how to make (1) work?
For reference, the bs_modal() source is here, and flexdashboard.js is here.
(1) This works:
---
title: "Untitled"
output: flexdashboard::flex_dashboard
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(bsplus)
```
Sidebar {.sidebar}
-------------------------------------
```{r}
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
bs_modal(id = "modal", title = "I'm a modal", body = "Yes, I am.")
bs_button("Click for modal") %>%
bs_attach_modal(id_modal = "modal")
```
(2) This doesn't work:
---
title: "Untitled"
output: flexdashboard::flex_dashboard
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(bsplus)
```
Sidebar {.sidebar}
-------------------------------------
```{r}
bs_modal(id = "modal", title = "I'm a modal", body = "Yes, I am.")
bs_button("Click for modal") %>%
bs_attach_modal(id_modal = "modal")
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
```
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 have the following code which creates a flexdashboard:
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
And I want to insert some HTML and javascript code. I tried this
Column
-----------------------------------------------------------------------
### Block 1
```{r}
<p>"This is a paragraph"</p>
<script>
alert("This is an alert")
</script>
```
But it doesn't work. Please, could you help me with this question? Thank you.
You can directly type the HTML code, without chunk. You can also use the tags function of the 'htmltools' package in a chunk (or the Shiny UI functions). For JavaScript, use a js chunk.
---
title: "TEST"
output:
flexdashboard::flex_dashboard:
orientation: rows
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r packages, include=FALSE}
library(flexdashboard)
library(htmltools)
```
Page
====================================
Row
-----------------------------
### HTML and JavaScript
<button id="btn">Click me</button>
```{js, echo=FALSE}
$("#btn").on("click", function() {
alert("You clicked the button!")
})
```
### HTML using 'htmltools'
```{r, echo=FALSE}
tags$button("Another button")
```
I'm trying to create active links in an RMarkdown document. In the code below, the basic kable table is perfect, but the datatable version turns the links into text
---
title: "Example"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(DT)
example.df <- data.frame("link"=c("[Tokyo](https://en.wikipedia.org/wiki/Tokyo)","[Paris](https://en.wikipedia.org/wiki/Paris)"), "country"=c("Japan","France"))
kable(example.df)
datatable(example.df)
Whoops, here's the answer: format the links as raw HTML not as RMarkdown syntax http://blogs.oregonstate.edu/cgrb/2019/08/06/r-tips-a-table-makeover-with-dt/
There are 2 changes needed to it to work with datatable.
Format the links as raw HTML, not Markdown
Include relevant escape arguments as to NOT escape the link column. For simplicity in this example, we use escape=FALSE
Here is a full reprex answer.
---
title: "Example"
output: html_document
---
```{r setup, include=TRUE}
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(DT)
example.df.kable <- data.frame("link"=c("[Tokyo](https://en.wikipedia.org/wiki/Tokyo)","[Paris](https://en.wikipedia.org/wiki/Paris)"), "country"=c("Japan","France"))
example.df.datatable <- data.frame("link"=c(
'Tokyo',
'Paris'),
"country"=c("Japan","France"))
kable(example.df.kable)
datatable(example.df.kable) # This does NOT show the links
datatable(example.df.datatable) # This does NOT show the links
datatable(example.df.datatable, escape=FALSE) # This does show the links
I want to create an html report with a table with icons (arrows) but while it works for shiny or flexdashboard it does not seem to wotk when I knit to html format. Is there a way to produce such a table in html output?
---
title: "Leads Report"
output: html_document
---
```{r global, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,fig.width = 14)
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(DF2$FCB-DF1$FCB > 0,
paste("<p>↑</p>"),
ifelse(DF2$FCB-DF1$FCB < 0,
paste("<p>↓</p>"),
paste("<p>⇆</p>")))
```
#### Table
```{r plot1, echo=FALSE,results='hide', message=FALSE, warning=FALSE }
knitr::kable({DF1}, sanitize.text.function = function(x) x,escape = F)
```
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)
```