I have an application created with flexdashboard. I included my R code in different chunks as it supposed to be (along with shiny and flexdashboard components).
If I try to run my application ( from batch file using rmarkdown::run or directly from Rstudio, it doesn't really matter) without changing the Rmd file first (just with a space more), the application stars but the chunks are not run.
Basically only the static page is shown and I see that the shiny server (my pc in this case) is in "listen" status.
At this point whatever interaction I do with buttons dropdown list has no effect on the application.
It seems that the chunks are not run if the Rmd file is up to date. There is a way to force the execution? I don't understand what I'm doing wrong.
If I change with a fake modification the rmd and I save it, then all the chunks are executed and the app run perfectly....
I run my app using the following code via batch file:
"D:\Data\v101285\Programs\R\R-3.5.2\bin\i386\R.exe" -e "rmarkdown::run('D:/Data/v101285/Marco/09_R_Projects/02_InteractiveRiskViewer/InteractiveRiskViewer.Rmd', shiny_args = list(launch.browser = TRUE))"
thanks a lot for the support
Edit:
For avoiding cache issues,as suggested in the comments, I included cache=FALSE in every chuck but still the issue persists. I noticed that Rmarkdown creates for every run a temp folder under "C:\Users.....\AppData\Local\Temp....\rmarkdown\". If I delete all the files than the chunks are run and the app works. There is a way to avoid this temp files?
I had a similar problem and i've found a solution:
https://github.com/rstudio/flexdashboard/issues/108
I just had to ensure that runtime: shiny is on its own line (not indented in the yaml header).
title: "Dynamic UI Test"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
Related
I suspect this is not possible or not very straightforward to do, but is there a way to create an HTML file of the current state of a quarto doc that has a shiny runtime? In other words, given the current state of the inputs and outputs, save the HTML file.
Is Shiny doing anything that's necessary for the HTML file to live on it's own when the inputs are fixed?
The use case I'm imagining is one in which you can interact with a doc in a way that Shiny enables, get the doc to a state that you want, then download and be able to share the HTML file that does not require a Shiny server.
I'm aware that I could just not use a Shiny runtime, and create a parameterized version of the report. But this would not allow the same level of flexibility and interactivity. Also, I'm aware that there are other (static/non-shiny) ways to achieve interactivity.
Here is a quarto doc with a shiny runtime:
---
title: "Test"
server: shiny
---
```{r}
#| context: server
```
There are no inputs in this Shiny quarto doc, which is not really the example I'm imagining. But in this simplified doc with no inputs, shouldn't I be able to download the HTML that's generated?
I have an R markdown file which I'd like to be available on my corporate Shiny Server.
According to R Markdown: The Definitive Guide I can add runtime: shiny to the YAML metadata at the top of the Rmd file to turn it into a Shiny document. I have done this and it works. If I click "Run Document" in RStudio it will run the Rmd and I will see the report with no problems.
My project is located in the ShinyApps directory where the Shiny Server is looking for apps to serve. When I hit the URL for this project I get the report without any charts. I just get broken image icons where the charts should be. (I am using RStudio Server so it is the exact same files being accessed by RStudio and Shiny Server).
R version 3.4.3, Shiny Server version 1.5.6.875
UPDATE: I have reproduced the behaviour with the simplest possible example. I created a new RStudio project - just a plain project - called TEST located in my ShinyApps directory. Then I created a new R Markdown file, which I called TEST.Rmd. This file is pre-populated with example RMarkdown using the cars and pressure built-in datasets. I changed the YAML header to include runtime: shiny. The RStudio "knit" button is replaced by the "Run Document" button, as expected, and clicking this runs the document and works as expected. Attempting to view the page via the Shiny Server has the same issue whereby the plot is not included; a broken image icon takes its place.
UPDATE 2: As requested, here is the Markdown file. It is literally the sample file generated by RStudio with the addition of runtime: shiny in the YAML header.
---
title: "Test RMarkdown"
author: "Michael Henry"
date: "4/6/2020"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
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:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
UPDATE 3: So I went hunting around the server looking for a log file for Shiny Server. I do not have any administrator privileges so I've never looked for this before, but I found a log file which included this: /lib64/libpango-1.0.so.0: undefined symbol: g_log_structured_standard. It turns out there is a bug in RHEL which has a fix available so I have put a request in with my administrator to apply the fix. I will report back after this has been applied as to whether it resolved my issue.
UPDATE 4: It turns out my RHEL server is up-to-date; it already has the version of glib2 suggested by the bugfix. The fact that I am still getting this error is therefore something that my administrator is going to escalate to Red Hat.
UPDATE 5: The Red Hat support suggested there was another glib2 so file lying around and it turned out that this was the case. Removing this file resolved the issue!
So, I think you might need to add some extra code to make the markdown application run as you expect in the Shiny Server environment
try wrapping the charts and plots with the following:
renderPlot({})
This gives the server an order to both run the plot and then make it available to the Shiny document. Shiny is a weird thing to straight up R programmers.
You are basically computing and creating things in an R environment and handing them off to a Javascript/HTML one which needs to know in its own language what to do. That renderPlot({}) tells the JS component how to promote the R output to your page.
You can see from this section of the reference document you linked to what the format is and how it is promoted to the page by Shiny.
If you are still stuck after doing this, reach back out and I will try to help trouble shoot!
Searching for the error message: /lib64/libpango-1.0.so.0: undefined symbol: g_log_structured_standard led to a known issue with RHEL whereby there was an older version of glib2 on the system that did not contain the symbol g_log_structured_standard. In my case the server was up-to-date and had the correct version of glib2, but there was another version of this library lying around which was causing the issue.
The moral of the story: search for the log files early and follow the leads contained therein!
It is sometimes desirable to create an R notebook that isn't self-contained. For example, one may want to load Mathjax from a local file of one's choosing, and to do so, self_contained must be FALSE. But I find that, by default, even the simplest R notebooks don't render properly when the YAML header includes self_contained: FALSE. Here is a minimal example:
---
title: "Notebook, not self-contained"
output:
html_notebook:
self_contained: false
---
Hello.
When this file is rendered with the default rmarkdown::render() options -- or when I "preview" the notebook by saving it in RStudio -- the resulting HTML file doesn't use default R Notebook CSS, and there is a lot of cruft at the top of the file, as shown in this related post. The problem seems to be that, by default, rmarkdown::render() uses clean = TRUE -- and for R notebooks, that means that the external directory containing all the dependencies (jquery, bootstrap, etc.) is destroyed as soon as it is created. For example, if the file above were titled "myNotebook.Rmd," calling rmarkdown::render() with default options would create a myNotebook_files directory that contains the dependencies -- and it would almost instantly delete that directory.
The problem goes away if you call rmarkdown::render() with clean = TRUE. But this solution isn't optimal. It leaves .md files in the output directory that I would like to be removed. And it doesn't work with RStudio shortcuts for knitting or previewing a notebook.
Is there any way to change the default clean = TRUE behavior of rmarkdown::render(), so that it doesn't remove the "_files" directory when self_contained is set to FALSE?
Curiously, this problem arises only when the output format is set to html_notebook -- not when it is set to html_document.
Using the chunk option eval=FALSE one can suppress chunk evaluation in an RMarkdown file or R Notebook when it is knit. Is there a way to make this apply during interactive running of the document in RStudio (i.e., making "run all chunks" skip certain chunks)?
I've got some chunks in the beginning of my analysis that take a while to run, which the later sections don't depend on. I want to be able to source the important parts of the code so I can continue writing the downstream stuff, without having to do it manually chunk-by-chunk so I can avoid the parts I don't need in my workspace for further writing.
I've set up the rmarkdown document with logical parameters meant to change which parts of the code need to get run - I meant these as control flags for when the code is actually finished and getting used, but I was hoping I could use those same parameters to exclude chunks from running in interactive mode (i.e., something like eval=params$run_part1).
Setting knitr::opts_chunk and knitr::opts_hooks only help you when knitting, not in interactive mode, so while I could be wrong I'm going to tentatively say you can't control that behavior with dynamic chunk options (yet).
As a workaround you could use interactive() and if blocks so that the code is only run when knitted. It would also mesh well with your logical parameters, despite the pain of having to be in a bracket block.
---
title: "R Notebook"
output:
html_document: default
html_notebook: default
---
```{r}
if (!interactive()) {
print("long running code")
}
```
```{r}
print(2)
```
```{r}
print(3)
```
Pressing "Run All Chunks Above":
Knitting:
If I have an R block in an Rmarkdown notebook, the code is visible in the rendered nb.html file. However, if I have a SQL block, I can't find a way to make the code visible in the rendered file.
However, if I generate an html_document (standard knitr) instead of an html_notebook, the rendered HTML does include the SQL code (and output).
Is there a way to get the notebook output to do something closer to what the knit output does?
I've also encountered this recently, Harlan, and began by asking if there's a way to get notebook output more like knit output.
I then wondered if there was a way to get knit output more like notebook output and realised that there was.
After asking the folks at RStudio, I learnt that you can add the following line to the YAML options in order to generate a html_document that, when rendered, enables the RMD to be downloaded. Specifically, use:
output:
html_document:
code_download: true
I now use that in all of my code and it works well. I hope it helps you, too.