Error in $: $ operator is invalid for atomic vectors


#1

I’m trying to get this application to run locally: https://github.com/holtzy/GenMap-Comparator

No matter what I do to change the file I am getting this error:

Listening on http://127.0.0.1:7062
Warning: Error in $: $ operator is invalid for atomic vectors
Stack trace (innermost first):
    49: tag
    48: tags$a
    47: tag
    46: tags$li
    45: FUN
    44: lapply
    43: buildTabset
    42: navbarPage
    41: shinyUI
     1: runApp
Error : $ operator is invalid for atomic vectors

From my research this shouldn’t be able to run online, but the creator has it running fine. Not sure where to go from here.


#2

You should try to create a minimal reproducible example of your issue.

Taking a quick look at the repo you linked to, I came up with this (since from the stack trace, the problem seems to be in the very beginning of the UI):

library(shiny)

# this mimics the behavior of `read.table("legend_sheet1.txt",sep="@")[,2]`
legend1 <- structure(
  c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), 
  .Label = c(
    "Home", 
    "The Genetic Map Comparator",
    "A user friendly tool to compare and characterize genetic maps", 
    "1. Please upload your maps:", 
    "... or select a demo dataset: ",
    "2. Explore your data           ", 
    "using the top buttons to navigate through the proposed views"
    "project leader:", 
    "other project members: ", 
), class = "factor")

ui <- navbarPage(
  ("The Gen Map Comparator"),
  tabPanel(
    h4(legend1[1]),
    "Tab content"
  )
)

server <- function(input, output, session) {}
shinyApp(ui, server)

However, this works fine for me. Does it error for you? You may consider upgrading the Shiny package if you’re on an old version. If it doesn’t error for you, try to build on my example until you can reproduce the same problem you get on the actual app. That will make it possible for us to help you debug it. Also, see this article (https://shiny.rstudio.com/articles/help.html) for help on asking for help, including how to write a minimal reproducible example.


#3

Ok, I took another look and actually figured out the problem: you cannot make a call to includeCSS (or, for that matter, include anything else that isn’t a tabPanel or a text string) directly inside navbarPage. Fortunately, there is an easy fix.

Here’s a repro of the problem:

library(shiny)

func <- function() {
  "hi there!"
}

ui <- navbarPage(
  title = "The Gen Map Comparator",
  theme = shinythemes::shinytheme("united"),
  
  # or in your case: includeCSS("www/genComp.css"),
  func(),

  tabPanel("Tab title",
    "Tab content"
  )
)

server <- function(input, output, session) {}
shinyApp(ui, server)

As you can see, you get the same error there. However, if you move func() to the inside of tabPanel (as long as it’s not the first argument), it will work as expected:

library(shiny)

func <- function() {
  "hi there!"
}

ui <- navbarPage(
  title = "The Gen Map Comparator",
  theme = shinythemes::shinytheme("united"),
  
  tabPanel("Tab title",
    # or in your case: includeCSS("www/genComp.css"),
    func(),
    
    "Tab content"
  )
)

server <- function(input, output, session) {}
shinyApp(ui, server)