4

I have a ShinyApp in a R package. One of the figure is made with {ggplot2} and function ggplotly. When I run the App in a fresh Rstudio session, the figure works. However, if I build my package using 'Install and Restart', then the following error message appears instead of the figure:

VECTOR_ELT() can only be applied to a 'list', not a 'NULL'

Reproduce the problem

I can reproduce the problem with a fresh new R package and a ShinyApp that is not even in the package. To do so, follow these steps in Rstudio:

Save the following ShinyApp in a file somewhere

This is a the basic example modified with {ggplot2} and [plotly}

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)
library(ggplot2)
library(plotly)

# Define UI for application that draws a histogram
ui <- fluidPage(

   # Application title
   titlePanel("Old Faithful Geyser Data"),

   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),

      # Show a plot of the generated distribution
      mainPanel(
        plotlyOutput("distPlot")
      )
   )
)

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

   output$distPlot <- renderPlotly({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      # bins <- seq(min(x), max(x), length.out = input$bins + 1)

      # draw the histogram with the specified number of bins
      g <- ggplot(data.frame(x)) +
        aes(x) +
        geom_histogram(bins = input$bins)

      ggplotly(g)
      # hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

In Rstudio

  • Create a new project for a R package (with hello World example)
  • Open this project
  • Open the app file you saved from code above (wherever it is) in your Rstudio session
  • Run app
  • Close app in navigator
  • Stop app in Rstudio
  • Modify a little the file and save. (Maybe not useful)
  • Build your package with "Install and Restart"
  • Run app again => The error should appear

    VECTOR_ELT() can only be applied to a 'list', not a 'NULL'

  • (Edit) Then if I run this directly in the console (although it works otherwise)

    ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species)
    ggplotly(ggiris)  
    

Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto), : VECTOR_ELT() can only be applied to a 'list', not a 'NULL'

Edit: It seems that if using devtools::install() instead of 'Install and Restart' the problem does not appear

I do not know if this comes from {plotly}, {ggplot2} or {devtools}.
I have:

  • {ggplot2} dev version : v2.2.1.9000 (Same appear with CRAN version)
  • {plotly} dev version 4.7.1.9000 (Not working). CRAN version : 4.7.1 (Not working).
  • {devtools} CRAN version 1.13.5 (Not working)
Sébastien Rochette
  • 6,536
  • 2
  • 22
  • 43
  • Do you also have this error with the code provided in the linked question? I don't. – F. Privé Feb 22 '18 at 15:01
  • Not if I only use the code. But if I encountered the problem in my shiny App, then the problem occurs for any `ggplotly()`, even if run in the console directly: `Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto), : VECTOR_ELT() can only be applied to a 'list', not a 'NULL'` – Sébastien Rochette Feb 22 '18 at 15:56

0 Answers0