How to render googlevis in flexdashboard - r

I'm trying to use GoogleVis with the new package FlexDashboard, which is like the intersection between a basic .Rd and shinyDashboards. It's basically a non-shiny dashboard.
Anyway, I'm trying to embed a googleVis object, which doesn't seem to be supported by default, but I can get the html to show up in the output, so there must be a way! Can we come up with some hack? Maybe combining either plot() or renderGvis() combined with some kind of hack? Ormessing with setting op <- options(gvis.plot.tag='chart')?
I have failed, but maybe someone else can figure it out?

Building on the awesome answer from Michal Majka at Conditional reactive logic shiny based flexdashboard you can do something like this
---
title: "Test gvisTable"
output:
flexdashboard::flex_dashboard:
orientation: rows
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(googleVis)
```
Column {data-height=350}
-----------------------------------------------------------------------
### Chart c
```{r}
#create a ui interaction:
uiOutput("dynamic")
#render the ui:
output$dynamic <- renderUI({
htmlOutput("myTable")
})
#here is your server activity:
output$myTable <- renderGvis({
gvisTable(Population )
})
```

Related

Getting Error object output not found when trying to render shiny flexdashboard from R script

I have a shiny flexdashboard that runs fine if I open the file directly and click Run Document in R Studio, however I am trying to set up an R script to run the dashboard. The script will find the markdown file and run partly through it but always throws an error once it gets to something like output$something <- renderUI(...). The error is
Error in output$select_file <- renderUI({ : object 'output' not found
A test markdown file for this issue is:
---
title: "example"
author: "hamburglar"
output:
flexdashboard::flex_dashboard:
theme: yeti
orientation: rows
vertical_layout: fill
runtime: shiny
---
#```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
#```
Home
=======================================================================
Sidebar {.sidebar}
-----------------------------------------------------------------------
> These are some notes
#```{r}
data(iris)
data(cars)
data(CO2)
files <- list(iris=iris, cars=cars, CO2=CO2)
output$select_file <- renderUI({
selectInput(inputId='file_choice',
label='Choose File',
choices=names(files)
)
})
uiOutput("select_file")
#```
Row
-----------------------------------------------------------------------
### Data
#```{r}
renderTable({
files[[input$file_choice]]
})
#```
And I've tried to use the following scripts with the same results:
library(flexdashboard)
library(shiny)
library(rmarkdown)
render("path/test_board.Rmd",
#output_file="Dashboard.html"
#flex_dashboard()
#"flex_dashboard"
)
For the path I've tried a shared drive path and my desktop and I've tried a number of different arguments that I've read will let the render function know to make a flaexdashboard (in comments in the render function). In all my attempts I get the Error saying that the output object cant be found. If anyone could offer any help I would greatly appreciate it.
In flexdashboard you don't need to use output. Just do:
---
title: "example"
author: "hamburglar"
output:
flexdashboard::flex_dashboard:
theme: yeti
orientation: rows
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
```
Home
=======================================================================
Sidebar {.sidebar}
-----------------------------------------------------------------------
> These are some notes
```{r}
data(iris)
data(cars)
data(CO2)
files <- list(iris=iris, cars=cars, CO2=CO2)
selectInput(inputId='file_choice',
label='Choose File',
choices=names(files)
)
```
Row
-----------------------------------------------------------------------
### Data
```{r}
renderTable({
files[[input$file_choice]]
})
```

Flexdashboard - hidden navbar tab using reactive values

I can hide a navbar page using the static value of show_hide but I cannot figure out how to do it with the reactive value r_show_hide(). I have also tried using isolate(ifelse...) and then r_show_hide (no parentheses) as well as reactiveVal() to no avail.
There is also an extraneous "> that shows up. Any help would be appreciated.
Update:
I created an issue https://github.com/rstudio/flexdashboard/issues/229
---
title: "-"
output: flexdashboard::flex_dashboard
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
show_hide <- "show" # "hidden"
r_show_hide <- reactive(ifelse(session$clientData$url_hostname == "127.0.0.1", "hidden", "show"))
```
Does work {.`r show_hide`}
=============================
### Should be `r show_hide`
Doesn't work {.`r reactive(r_show_hide())`}
===============================
### Should be `r renderText(r_show_hide())`
Ok, this took me a while figuring out.
The fundamental problem is that r chunks in curly brackets of the flexdashboard navbar evaluate in a non-reactive context, compared to the r chucks that build the content of each page, which are evaluated in a reactive context. For this reason you cannot use a reactive such as r_show_hide() to trigger the argument hidden/show of the navbar page, but you can use r_show_hide() in a renderText() function within the page.
So the actual question is, how to access a reactive value from a non-reactive context. The answer is isolate() and is explained here.
Below I provide an example using your code.
---
title: "-"
output: flexdashboard::flex_dashboard
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
show_hide <- "show" # "hidden"
r_show_hide <- reactive(ifelse(session$clientData$url_hostname == "127.0.0.1", "hidden", "show"))
```
Does work {.`r show_hide`}
=============================
### Should be `r show_hide`
Doesn't work {.`r isolate(r_show_hide())`}
===============================
### Should be `r renderText(r_show_hide())`

using output of shiny in markdown

I’m working in a R notebook and I’d like to add some interactivity using shiny.
So, I need that the user provide some text in an input field. Then, this text will used in different R chunks in the notebook. However, I wasn’t able to find the best way to do this. Here is an example of what I’m trying to do:
---
title: "R Notebook"
output: html_document
runtime: shiny
---
```{r}
data <- reactive({
as.character(input$my_mol)
})
```
```{r}
textInput("my_mol", "Please provide an ID", "MyID_1")
```
```{r}
renderPrint(data())
# is there any way to get the text output in a variable and using it in a different R chunk?
#something like:
#my_output <- renderPrint(data())
```
```{r}
# Then, I'd like to using it on this R chunk
#pba3 <- fromJSON(paste0(baseur_sim, url_encode(my_output), ".json?limit=50"), flatten=TRUE)
```
Thanks!

How to embed shiny app on SharePoint with Iframe tag

I have a very simple app showing some data.
How do you embed this in a SharePoint site using using iframe ?
or is there an easier way to do this ?
library(ggplot2)
library(shiny)
library(DT)
library(readr)
PRTypeCount <- read_csv("H:/SP/PRTypeCount.txt")
ui <- navbarPage(
title = 'PRTypeCount',
tabPanel('PRTypeCount', DT::dataTableOutput('PRTypeCount')))
server<-function(input, output) {
output$PRTypeCount <- DT::renderDataTable(
DT::datatable(PRTypeCount, options = list(pageLength = 25))
)
}
shinyApp(ui = ui, server = server)
If you do not have a shiny server your best bet is probably the flexdashboard package or making individual components and arranging them in SharePoint designer. Here is a quick example, you will be somewhat limited with interactivity as compared to shiny -- there are some things you can do with plotly, ggiraph, and some other packages. For many use cases this can be perfectly adequate:
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
DT::datatable(iris)
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
hist(iris$Sepal.Length)
```
### Chart C
```{r}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
Once you knit this rmd file to html. You make can make a copy of the HTML file and change the extension to .aspx.
Then you can put this .aspx file in in a document library.
Then add a page viewer web part where you want the content displayed, linking it to the .aspx file in the document library.

get selected row in a datatable in an interactive document using Rmarkdown and shiny

I am exploring the use of DT:datatable in an interactive document using Rmarkdown and shiny (I have not used datatable before).
I am able to create a document that plots a data table:
---
title: "Test DT"
output: html_document
runtime: shiny
---
```{r echo=FALSE}
datatable(iris)
```
Clicking in a row in the datatable highlights a row. Is there any way to access the selected rows without implementing a shiny server? How?
You have to use an output$id for it to work. Just how you would do it in shiny itself
---
title: "Test DT"
output: html_document
runtime: shiny
---
```{r echo=FALSE}
library(DT)
DT::dataTableOutput('irisTable')
output$irisTable = DT::renderDataTable(iris, selection = 'multiple')
p("By default DT allows multiple row selection. Selected rows are...")
renderPrint(input$irisTable_rows_selected)
```
DT also allows column and cell selection as well as preselection. See documentation

Resources