How to render a list


#1

My function returns a list that contains a list and a variable
return(list(list(X), variableName))

[A, B] <- functionName(filename)

I try to use renderText(), but I get the error: list cannot be handled by cat().

How can I print the list -list(X) -returned by the function.


#2

You need to include a reprex of your code so we can duplicate what happens when you run it. It should contain the input your code needs and produce the output or error you are encountering. If possible you should show the results you are looking for.

There are lots of people here who want to help you get your code working but you have to do your part by making it as easy as possible for them to do that. Posting your code in a reprex is the way to do that.

Here is a link that explains reprex:

https://www.tidyverse.org/help/

If you have any problems with reprex’s just post another topic here and you will get a lot of help get reprex’s working.


#3

I tried to right a simple equivalent of the real program. The real program reads a file, extracts one column and converts it into a list. Here I am using a dummy list. If I return a single value, everything works fine. This is what I get when I run app.R: “error: argument 1 (type ‘list’) cannot be handled by ‘cat’”

I could not make reprex() work this time. I will keep trying

library(shiny)

ui <- fluidPage(
  
  sidebarLayout(
    sidebarPanel(
      column(width = 10,
             conditionalPanel(
               condition = "input.btn == true",
               selectInput("value", label = h4("Do you have a params file ready to use (Y/N)?"),
                           choices = c("", "Y", "N"), selected = NULL)
               
             ),
             conditionalPanel(
               condition = "input.value == 'Y'",
               helpText(h4("Select your params file")),
               fluidRow(
                 column(width = 10, fileInput("file", "upload the file", accept = ".tsv", placeholder = "No file selected", multiple = FALSE))
               )
               # useShinyjs(),  # Include shinyjs
               # extendShinyjs(text = jscode, functions = c("closeWindow")),
               #actionButton("close", "Stop glycoPipe")
               
             )
     
        )
    ),
    mainPanel(
      
      
      textOutput("checkedFile")
      
    )
)
)

glycoPipe <- function(inFileName){
  
  list[valid, outL] <- extractParams(filename)
  
  list(valid = valid, outL = outL)
}

extractParams <- function(filename){
  
 valid = "valid"
 outL <- list(1,2,3,4,5)
 return(list(valid, outL))
}

server <- function(input, output){
  
  output$contents <- renderTable({
    inFile = input$file
    inFileName = input$file$name
    if(is.null("inFile")){
      return()
    }
    
    req(inFile)
    validate( need(file_ext(inFile) %in% c(
      'tsv'
    ), "Wrong File Format. The selected file is not a valid tab-separated PARAMS file try again. If
     you do not have a parameters.tsv file in your directory stop clycoPipe create a file and re-start glycoPipe"))
    read.delim(inFile$datapath, quote = "", sep = '\t')
    
  })
  
  output$checkedFile <- renderText({
    inFile <- input$file
    inFileName <- input$file$name
    result <- glycoPipe(inFileName)
    result$outL
    
  })
 
}

shinyApp(ui = ui, server = server)

#4

I fixed the problem by using renderUI({}) instead of renderText({}). It seems that renderText({}) can not be used with lists.