Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print lists of lists of uneven length in Shiny

Tags:

r

shiny

I have a list shown below. I want to print it as it looks in my shiny application. I tried print(unlist(ls)) where ls is the list shown below but it just printed numbers. I also tried print.char.list from the Hmisc package but it gave error saying

Error in x[[1]][1, ] : incorrect number of dimensions. 

So how can I print the names too? Thanks in advance.

$money
bankaccount       cryin   desperate      feelin      likely      loaded      poppin       build      moment 
       0.73        0.73        0.73        0.73        0.73        0.73        0.73        0.62        0.59 
      spend       spent 
       0.51        0.51 

$matter
becauseit    racest   spanish     found    whites     races 
     0.63      0.63      0.63      0.56      0.56      0.55 

$little
appropriate    carrying       usual 
       0.56        0.56        0.56 

$still
    cloth     codes glamorous     grade 
     0.57      0.57      0.57      0.57 
like image 667
Abhinav Avatar asked Oct 17 '25 11:10

Abhinav


1 Answers

How about this:

library(shiny)
mylist <- list(letters[1:4], letters[1:5], letters[1:2], letters[1:6])

server <- function(input, output) {

  output$console <- renderPrint({
    print(mylist)
  })

}

ui <- shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(
    ),
    mainPanel(verbatimTextOutput("console"))
  )
))

shinyApp(ui = ui, server = server)

At first i have created example of list of lists (as you have not provided the data in a proper format that is easy to read directly into R, please consider posting data next time correctly) and then easily printed it as an console output with renderPrint().

like image 64
Mal_a Avatar answered Oct 20 '25 00:10

Mal_a