Shiny Module Error: cannot coerce type 'closure' to vector of type 'character'

I am attempting to transfer my shiny App into a module format to be able to expand it easier. This code analysis flow cytometry data (.fcs files). I am unsure how to link that files that I am analyzing to this post.

I think that my UI and Server modules are not communicating, but cannot find the issue. The error code I am getting is: cannot coerce type 'closure' to vector of type 'character'.
I have gone through a few different module tutorials, but it hasn't clicked yet.


library(shiny)
library(flowCore)
library(flowMeans)
library(flowViz)
library(grid)
library(plotrix)
library(rgl)


######## Module 1: FCS Gating
######## Input: FCS file
######## Output: FSC, SSC plot


fcsGatingServer<-function(id){
  moduleServer(id, function(input, output, session) {
   
 output$plotSSC <- renderPlot({ 
       
filePath<-reactive(input$file$datapath)

myfcs <- read.FCS(paste(filePath), alter.names=TRUE)

name<-"CD54+ Cells"

plot(myfcs[,c("FSC.A", "SSC.A")],pch=".",  xlab="FSC.A", ylab="SSC.A")

   })
  })
}

fcsgatingUI<-function(id) {
  ns<-NS(id)
  
  sidebarLayout(
    sidebarPanel(
      fileInput(ns("file"), label ="BDS77 CD54 FCS File", multiple = F, accept = ".FCS", buttonLabel ="Browse CD54")
      
    ),
    mainPanel(
      plotOutput(ns("plotSSC"))
    )
      )
}

server <- function(input, output, session) {
  fcsGatingServer("1")
}

ui <- fluidPage(
  fcsgatingUI("1")
)

  shinyApp(ui, server)

Two things

  1. you should not define reactive within a render function. If you want to use the reactive there define it on its own , earlier, above.

  2. When you do come to use it , it'd a reactive so to get to its content you need to call it with open and closing brackets after its name as it if was a function.
    I.e.

paste(file.path())

Thank you very much! I moved the reactive one line up and the code works

moduleServer(id, function(input, output, session) {
  filePath<-reactive(input$file$datapath) 
 output$plotSSC <- renderPlot({ 
       

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.