Shiny Server deployment in Azure

I have successfully installed RStudio Server and Shiny Server using Azure VM, and able to get up the default page of sample-apps/hello.

However, when I try adding some simple code to the sample-apps/hello, it breaks.

library(shiny)

# Define server logic required to draw a histogram
shinyServer(function(input, output) {

  # Expression that generates a histogram. The expression is
  # wrapped in a call to renderPlot to indicate that:
  #
  #  1) It is "reactive" and therefore should be automatically
  #     re-executed when inputs change
  #  2) Its output type is a plot

  output$distPlot <- renderPlot({
    x    <- faithful[, 2]  # Old Faithful Geyser data
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
    
    library(downloader)
    url <- "https://raw.githubusercontent.com/genomicsclass/dagdata/master/inst/extdata/msleep_ggplot2.csv"
    filename <- "msleep_ggplot2.csv"
    if (!file.exists(filename)) download(url,filename)
    msleep <- read.csv("msleep_ggplot2.csv")
    head(msleep)
  })
})

I have installed libraries "downloader" and "dplyr" in RStudio.
The shiny server log says: 
Listening on http://127.0.0.1:45969
Warning: Error in library: there is no package called ‘downloader’
  169: stop
  168: library
  167: renderPlot [/srv/shiny-server/DataAnalyticsPortal/server.R#20]
  165: func
  125: drawPlot
  111: <reactive:plotObj>
   95: drawReactive
   82: origRenderFunc
   81: output$distPlot
    1: runApp

Can anyone help?
Thanks.

Shiny runs on an independent R session with its own user so in order for shiny to be able to use packages you have to install them as superuser, try installing from the terminal with this command

sudo su - -c "R -e \"install.packages(c('downloader', 'dplyr'), repos='http://cran.rstudio.com/')\""
1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.