Gaius Augustus
Gaius Augustus

Reputation: 970

R Studio - Knitr to interactive HTML - Error, execution halted

R Version: 3.2.1; RStudio Version: 0.98.1103

I am trying to Knit a R Markdown file. But am getting the following warnings and error.

Warning messages:
1: In FUN(X[[i]], ...) :
  Package 'plyr' not available in repository or locally
2: In FUN(X[[i]], ...) :
  Package 'ggplot2' not available in repository or locally
3: In symlinkExternalPackages(project = project) :
  The following external packages could not be located:
- "plyr", "ggplot2"
Loading required package: reshape2
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called 'reshape2'
Error in loadNamespace(name) : there is no package called 'rmarkdown'
Calls: :: ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

I've made sure that all of the packages listed are installed, and I've added library(package) for each package listed (ggplot2, reshape2, rmarkdown). I assume I'm missing something simple.

I also tried moving all my packages back to the default directory: as suggested here, and checked my .libPaths() to be sure my library directory was there, which it is.

Below is a simplified version of my R markdown file:

 ---
    title: "Gain Loss Plot - All Samples"
    author: "Gaius"
    date: "Thursday, September 24, 2015"
    output:
      html_document:
        toc: yes
    runtime: shiny
    ---

    In order to more completely visualize how samples might be related, we are going to create a few interactive plots.

    # Samples by Arm

    ```{r loadlibraries, echo=FALSE}
    library(rmarkdown)
    library(graphics)
    library(ggvis)
    library(ggplot2)
    library(plyr)
    library(reshape2)
    library(data.table)
    library(grDevices)
    ```

    ```{r prepdata, echo=FALSE}

    C01p <- data.table(read.delim("~/_2015_CNV/2015-09-23_CCCC_GLredo_rmvdup-missedlowpurity/chr/01p.txt"))
  #LOAD a bunch of other files just like the one above

    C01p[,Chr.Arm := "01p"]
    #Subset all files as shown in the line above

    #bind all files together
    All.Chrom.Stats  <- rbind(C01p,C01q,C02p,C02q,C03p,C03q,C04p,C04q,C05p,C05q,C06p,C06q,C07p,C07q,C08p,C08q,C09p,C09q,C10p,C10q,C11p,C11q,C12p,C12q,C13q,C14q,C15q,C16p,C16q,C17p,C17q,C18p,C18q,C19p,C19q,C20p,C20q,C21q,C22q)

    #Get just data necessary for creating plots
    Prop.Gain.thresh <- All.Chrom.Stats[Prop.Gain > 0.50]
    Prop.Loss.thresh <- All.Chrom.Stats[Prop.Loss > 0.50]
    ```


    ## Proportion Gained, Threshold > 0.5


    ```{r prop.gain, echo=FALSE}
    all_values <- function(x) {
      if(is.null(x)) return(NULL)
      paste0(names(x), ": ", format(x), collapse = "<br />")
    }

    Prop.Gain.thresh %>% 
      ggvis(~Chr.Arm, ~Prop.Gain) %>% 
      layer_points( fill = ~Sample ) %>% 
      add_tooltip(all_values, "hover")
    ```


    ## Proportion Lost, Threshold > 0.5

    ```{r prop.gain, echo=FALSE}
    all_values <- function(x) {
      if(is.null(x)) return(NULL)
      paste0(rev(names(x)), ": ", rev(format(x)), collapse = "<br />")
    }

    Prop.Loss.thresh %>% 
      ggvis(~Chr.Arm, ~Prop.Loss) %>% 
      layer_points( fill = ~Sample, shape = ~Sample ) %>% 
      add_tooltip(all_values, "hover")
    ```

UPDATE: I tried creating a new R markdown file and used the basic template given by RStudio to try to knit. It worked and output the file correctly.

Then I added runtime:shiny to the YAML header. It stopped working (giving same error as above).

I then removed runtime:shiny from the header via UNDO, and it still won't work. Error is the same as in my original question.

Upvotes: 1

Views: 3001

Answers (1)

Matt Brigida
Matt Brigida

Reputation: 291

You are using runtime: shiny but you have no shiny elements. In other words you have no ui input functions or server render (renderPlot(), renderTable(), etc) functions. See here for what would be in a shiny presentation: http://shiny.rstudio.com/articles/interactive-docs.html

The specific error is likely due to objects not being available across all shiny widgets in a document. You would have to load the package in each widget, or use something like a global.R file. See the link below:

https://rstudio.github.io/shiny/tutorial/#scoping

Upvotes: 1

Related Questions