getParseData returns NULL when published in a shiny app to Rstudio Connect

Hi everyone,

I asked this question in Rstudio Support, but they were pointing me to standard help files and docs, which I've already gone through. I have a shiny app that parses the ui.R file and, along with getParseData and a bit of tidyverse magic, neatly turns the ui into a dataframe where I can store and use metadata like labels, defaults, etc.

When I run locally/in rstudio server, the function works great. However, when I publish to connect, it breaks my app as the getParseData function returns NULL. Reprex below

parse_ui <- function(.file = here::here("ui.R")){

  file_text <- readLines(.file)
  parsed_ui <- parse(text = file_text)
  parsed_ui_data <- utils::getParseData(parsed_ui, includeText = TRUE)
  print(paste("Is parsed UI NULL? : ",is.null(parsed_ui)))
  print(paste("Is parsed UI Data NULL? : ",is.null(parsed_ui_data)))


I have a simple hack -- add an if else is.null to the function above such that when the file runs locally, write it to a feather file and when its published / returning NULL, read the last saved version instead, but that isn't a bulletproof solution.

Any ideas why this isn't working or better solutions would be appreciated!


1 Like

This probably happens because of the way sandboxing on Connect provides separation between processes and users.

Also, using parsing your source code to define configuration settings sounds like an anti-pattern to me. A better pattern would be to define all your metadata and settings in a configuration file, then let the shiny app itself adjust to the config file.

A great way to do this is to use the config package. See also the managing credentials section of

Yes, I suspect the problem is the here::here() piece. If I remember correctly, I have seen the here package have some weird effects on Connect.

Why don't you try just using a relative path from the base of the Shiny application and see if that fixes the problem?

As a debugging step, I would add debugging statements like message(getwd()) and message(.file) to get a better picture of what is happening inside of Connect. As @andrie mentioned, the sandboxing process may be a part of the problem here... or perhaps something needs to be tweaked in the here package.

The problem is with the keep.source option, which is not TRUE in all environments.

Running R standalone:

R --slave -e 'getOption("keep.source")'
# => [1] FALSE

You can either set the keep.source option:

  options(keep.source = TRUE)
  parsed_ui <- parse(text = file_text)

Or specify the keep.source argument:

  parsed_ui <- parse(text = file_text, keep.source = TRUE)
1 Like