I have a Shiny app with 3 R files (ui.r, server.r and global.r)
For normal .R documents I can just embed code like this:
#' ---
#' title: "User Interface for My Awesome App"
#' author: "Serban Tanasa"
#' date: "Current Version Updated - 2015.07.09"
#' output: html_document
#' ---
and so on and so forth, and assuming I've sprinkled comments around the whole script, I can press the handy "Compile Notebook" button in RStudio-Server:
...and compile it into a decent documentation. With the shiny app however, trying to compile the ui i get the following error.
output file: ui.knit.md
Error: path for html_dependency not provided
Execution halted
Is there some way to get around this?
This is for R 3.2.1, with RStudio Server Version 0.98.1103, and Shiny 0.12.0
Shiny is meant to be run as an application, not to be compiled into a document, I don't think that button is designed to work with Shiny files.
Related
In Rmarkdown, I cannot read files that I can read from the console and in an R script, because Rmarkdown is not following the same paths as my R scripts and console commands.
Here is a minimum reproducible example:
Create new project test.Rproj
Create a subdirectory called scripts
Run the following R Script scripts/test.R:
test <- as.data.frame(c(1, 2, 3))
dir.create("data")
write.csv(test, "data/test.csv")
rm(test)
test <- read.csv("data/test.csv")
Quit R, and reopen test.Rproj.
Knit the following Rmarkdown document (scripts/test.Rmd):
---
title: "test"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
_```
```{r read-data}
test <- read.csv("data/test.csv")
_```
Yields the following error: Quitting from lines 12-13 (test.Rmd)
Error in file(file, "rt") : cannot open the connection
Calls: ... withVisible -> eval -> eval -> read.csv -> read.table -> file
Execution halted
(Note, the backticks in the .Rmd file are properly specified -- I added underscores above so that the backticks appeared in the code block.)
Two seemingly related issues:
I can read the test.csv file via Rmarkdown if it is in the scripts subdirectory, rather than the data subdirectory.
When I run list.files() from the console or script, I receive of list of files in the top-level directory (i.e., where test.Rproj is located), including the data and scripts subdirectories. When I run list.files() from Rmarkdown, I get a list of files in the scripts subdirectory.
How can I fix this problem?
Session info:
R version 4.1.0 (2021-05-18)
RStudio version 1.4.1717
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.5.1
Try something that looks like this as I am not sure of the nature of your `R Markdown.
test <- readRDS(here::here("data/test_data.rds"))
The bottom line is to use the here function from the here package.
When you knit a document in RStudio, by default the working directory is set to the current directory of the Rmd document (so that would be the "scripts" folder). Since the "scripts" folder does not contain the "data" directory, you get that error. You can change the default to use the project root directory if you prefer. That's an option in the RStudio Global Options menu.
See See https://bookdown.org/yihui/rmarkdown-cookbook/working-directory.html for more info
I have an Rmarkdown file which currently does not need to source() to other scripting files. There are currently two parameters in the YAML: a numeric input and a file upload for .CSVs
When I "knit with parameters" locally the file runs fine, I've even moved it out of my existing RProj to various other locations on my computer to make sure the working director doesn't matter and the place I'm grabbing .csv files from doesn't impact the knitting process.
When I attempt to publish to my RStudio Connect account I get the following two errors:
Error in file(file, "rt") : cannot open the connection
Calls: local ... withVisible -> eval -> eval -> read.csv -> read.table -> file
This is my current YAML for reference:
---
title: "CPR Report Card"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
prettydoc::html_pretty:
theme: cayman
params:
data:
label: "Input Zoll Dataset:"
value: ".csv"
input: file
age:
label: "Age of Patient"
value: 0
input: numeric
min: 0
max: 17.75
step: .25
---
So, locally and across computers the file works fine. Seems like it should publish ok to RStudio Connect but currently isn't. This is my first foray into Connect, any help is greatly appreciated!
After communicating with the RStudio Connect support service, using read.csv() from an Rmarkdown file causes issues since the markdown does not have a reactive component to interact with the user's file system. If you wish to have this functionality it's best to look into developing a Shiny application.
I'm trying to upload a Shiny App to shinyapps.io in Showcase mode. According to those directions, one includes a text file named DESCRIPTION (no extension) with the following fields (this is from the example linked above:
Title: Hello Shiny!
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: GPL-3
DisplayMode: Showcase
Tags: getting-started
Type: Shiny
This answer describes the same process - but, it seems like it doesn't work any longer.
When I try to publish a Shiny App with a DESCRIPTION file like the one int he example, the following error is returned:
Preparing to deploy application...DONE
Uploading bundle for application: 88219...Error in readDcf(file.path(project, "DESCRIPTION"))[, "Package"] :
subscript out of bounds
Calls: <Anonymous> ... suppressMessages -> withCallingHandlers -> <Anonymous> -> unname
Execution halted
For what it's worth, I tried excluding different fields from the DESCRIPTION file, even trying one with only DisplayMode: Showcase included. I also tried saving the file in different editors.
This Google Groups thread seems to suggest this is a bug, but since there doesn't seem to be a question posted about it other than when this worked, I hoped to see if anyone had found or could suggest a fix.
EDIT: I posted an Issue on the Shiny Apps GitHub page.
Installing the latest version of packrat from GitHub (i.e., devtools::install_github("rstudio/packrat") did the trick, thanks to this GitHub Issue suggestion. Installing the latest CRAN version (install.packages("packrat")) did not work.
I open my shinyapp on the shiny server in Showcase mode using DESCRIPTION file with additional fields that were not described in documentation and it works.
Package: MyShinyApp
Version: 1.0
Title: Hello Shiny!
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: GPL-3
DisplayMode: Showcase
Tags: getting-started
Type: Shiny
Adding fields Package and Version will resolve this error ERROR system error 71 (Protocol error) [description=Version field not found in...]
I have created several shiny apps to embed in single Rmarkdown file.
I am using Amazon ec2 Ubuntu machine for hosting my shiny apps and rstudio. All the working apps are at /srv/shiny-server.
To do this, I create another folder for Rmarkdown single file in /srv/shiny-server. The individual chunks are running but Run Document commands is giving an error:
ERROR: cannot open the connection
I am using following R markdown code:
### App 1 goes here
```{r, echo=FALSE}
library(shiny)
shinyAppDir(
"/srv/shiny-server/App1",
options=list(
width="100%", height=550
)
)
```
### App 2 goes here
```{r, echo=FALSE}
library(shiny)
shinyAppDir(
"/srv/shiny-server/App2",
options=list(
width="100%", height=550
)
)
```
## Likewise ...
Not sure this will answer your question, but I encountered this problem and here's what I found. I'm running a shiny server on an Ubuntu EC2 instance. Also, I didn't create shiny apps the same way you did, instead I embedded interactive visualizations in R Markdown using ggvis and the shiny runtime like so:
---
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
html_document:
theme: readable
toc: yes
toc_depth: 3
runtime: shiny
---
Here are the two things that caused my problem:
Wrong paths to sourced code or data. You can provide absolute paths or paths relative to where your Rmd is located.
Using cache = TRUE in code chunks.
You can't cache things and when you do it causes the "cannot open the connection" error.
I'm trying to deploy an R markdown document on the shinyapp.io server.
I have followed the steps as described here.
However, step 8 indicates the presence of a "deploy" button. This button is missing.
As an alternative I have tried :
to open a new R script
Navigate to the Working Directory for my .Rmd file
Ran the following command: deployApp( appName = "Titanic")
Logs indicated everything was being uploaded correctly. However my destination page indicated 'not found'.
My questions:
Why did the 'deploy' button not show?
Why does my page indicate 'not found'?
Below you can find the header I used in the markdown document.
title: "KAGGLE - TITANIC SURVIVAL ANALYSIS"
output:
html_document:
toc: true
theme: spacelab
number_sections: true
runtime: shiny
Thank you in advance
Issue solved with R Studio version
Version 0.99.451 – © 2009-2015 RStudio, Inc.
!Note: In the newest version the deploy button has been replaced with Publish
This has not been adapted in the official shiny documentation yet. The screenshot below is the view you get once a first publish (formerly called deploy) action has been taken.