Im tying to use a function to generate plotly charts within flexdashboard.
---
title: "Single Column (Fill)"
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(plotly)
```
### Chart 1
```{r}
pltFunction(x,y)
```
If i click the green arrow, which says "run current chunk", the function works and plots the graph underneath the code chunk.
However, if i click knit, i get:
Error in pltFunction(x,y) : could not find function "pltFunction"
Calls: ... handle -> withCallingHandlers -> withVisible ->
eval -> eval
I'm very new to shiny et al, apologies for the simple question here, but can flexdashboard see the global environment? The function and all the data it needs are there.
Thank you!
Related
I am trying to output the flexdashboard template created by Rstudio.
it compiles the .md file and then fails on curl:
Error in curl::curl_download(url, dest, handle = handle, quiet = FALSE, :
schannel: failed to receive handshake, SSL/TLS connection failed
Calls: ... dep_func -> read_gfont_url -> download_file ->
this is inside a firewall and github is blocked. CRAN is allowed. if anybody knows what is it that flexdashboard tries to get I can get it and install it in other ways.
---
title: "mytitle"
output:
flexdashboard::flex_dashboard:
theme:
bg: "#101010"
fg: "#FDF7F7"
primary: "#ED79F9"
base_font:
google: Prompt
code_font:
google: JetBrains Mono
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
# Install thematic and un-comment for themed static plots (i.e., ggplot2)
# thematic::thematic_rmd()
```
Column {data-width=650 .tabset}
-----------------------------------------------------------------------
### Chart A
```{r}
```
### Chart B
```{r}
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart C
```{r}
```
### Chart D
```{r}
```
it is the fonts. after removing the fonts from the title section it can produce output. strangely, it does not work with the fonts even after I downloaded and installed the fonts outside Rstudio.
I´m new at R. I was trying to knit a Rmd file in RStudio into a pdf, but it presents the following error:
Quitting from lines 17-20 (projeto_final_20220429.Rmd)
Error in .External2(C_dataviewer, x, title) : unable to start data viewer
Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> View
Execution halted
The code written in those lines was this:
library(readr)
despesas_municipios_saude_educacao <- read_csv("despesas_municipios_saude_educacao.csv")
View (despesas_municipios_saude_educacao)
Is there anyone who can help me?
On MacOS, knitr attempts to load the X11 library in order to view the data frame, which fails because knitr isn't designed to interact with an end user. Regardless of the underlying operating system, since utils::View() is meant to work in a windowing environment (e.g. RStudio, RGui, R Tools for Visual Studio, etc.), it can't be used to print a data frame in an R Markdown document.
---
title: "Error with View()"
output: html_document
date: "`r Sys.Date()`"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## A header
Here is a reproducible version of the stackoverflow question [Execution Halted when Knitting](https://stackoverflow.com/questions/72068679/execution-halted-when-knitting-in-rstudio).
```{r mtcars}
data(mtcars)
View(mtcars)
```
...generates the following error:
To display a subset of data in a markdown file, one can use head() instead of View().
---
title: "Error with View()"
output: html_document
date: "`r Sys.Date()`"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## A header
Here is a reproducible version of the stackoverflow question [Execution Halted when Knitting](https://stackoverflow.com/questions/72068679/execution-halted-when-knitting-in-rstudio).
```{r mtcars}
data(mtcars)
head(mtcars)
```
...and the output in HTML:
We can improve the look of the output by turning off echo on the R chunk used to print the table, and use knitr:kable() to format the data frame.
We use the following R Markdown code, including the "pipe" argument to appropriately space the columns in the output.
We can make the output look nicer with `knitr::kable()`.
```{r kableVersion,echo=FALSE}
library(kableExtra)
kable(head(mtcars),"pipe")
```
...and the output renders like this in HTML:
I would like to include external markdown file; however, I could not handle it on RStudio so far. If I manually copy/paste the content of about.md into main.R, there is no issue. I mean setting up everything related with flexdashboard is fine. On the other hand, I have tried to reinstall rmarkdown package and import it by library("rmarkdown"). This is not fair enough because flexdashboard has already its internal one. So it should not be related with whether the rmarkdown installed or not apart from flexdashboard installation. Any suggestions ?
Thanks
I have prepared minimal code with its output as below:
'about.md'
test1
=======================================================================
**testttt**
testttt
**testttt2**
testttt
main.R
---
title: "test"
author: "test"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
```{r}
includeMarkdown('about.md')
```
The output:
Quitting from lines 17-18 (minimal.Rmd)
Error in includeMarkdown("about.md") :
could not find function "includeMarkdown"
Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval
Execution halted
The function includemarkdown is from the package htmltools. So you have to load the library or use:
```{r}
htmltools::includeMarkdown('about.md')
```
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())`
Following on from this question... I am not sure where to set knitr option if I want to output a separate file of R code. The following does not provide the expected additional .R files in my working directory.
---
output: ioslides_presentation
---
```{r setup, include=FALSE}
library("knitr"); purl("myfile.rmd")
#library("knitr"); knit("test_tangle.Rmd", tangle = TRUE)
#opts_knit$set(tangle=TRUE)
```
## Slide with Plot
```{r, echo=TRUE}
plot(cars)
```
but an error message...
Quitting from lines 6-7 (myfile.rmd)
Error in readLines(if (is.character(input2)) { :
cannot open the connection
Calls: <Anonymous> ... withVisible -> eval -> eval -> purl -> knit -> readLines
Execution halted
I recommend you to use the hook_purl function instead. The function purl() (or equivalently, knit(tangle = TRUE)) may fail to work in certain cases, and the hook function hook_purl() is more reliable. See ?hook_purl for more information.
---
output: ioslides_presentation
---
```{r setup, include=FALSE}
library("knitr")
knit_hooks$set(purl = hook_purl)
```
## Slide with Plot
```{r, echo=TRUE}
plot(cars)
```
Then as you knit the document, the R script will be automatically generated.