5

I have a shiny app that has a lot of input values. I'd like the input values to be easily perusable and/or exportable so I'd like to put them into a table format.

Previously, I had data.table(a=input$a,b=input$b,...) but this is not a very effective way of doing things.

Aim

Present all input values in a table output in shiny without having to write each input variable by hand

Background

A shiny input object is of str:

List of 1
 $ impl:Classes 'ReactiveValues', 'R6' <environment: 0xf798e60> 
 - attr(*, "readonly")= logi TRUE
 - attr(*, "class")= chr "reactivevalues"
  • rbindlist results in an error: Item 1 of list input is not a data.frame, data.table or list
  • Similarly as.data.frame gets: cannot coerce class ""reactivevalues"" to a data.frame
  • I then found ReactiveValuesToList()which the docs say works like as.list() but the object won't convert to inside rbindlist()

MWE

server <- function(input, output) {
  output$distPlot <- renderPlot({
    hist(rnorm(input$obs), col = 'darkgray', border = 'white')
  })

  # This is the bit I'm having trouble getting to work
  output$inputvals<-renderTable({
    as.data.frame(reactiveValuesToList(input))
  })
}

ui <- shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(
      sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100)
    ),
    mainPanel(plotOutput("distPlot"), tableOutput("inputvals"))
  )
))

shinyApp(ui = ui, server = server)
3
  • It works for me. What versions of shiny are you using? Commented Jan 27, 2015 at 11:43
  • shiny_0.10.2.2 - will clean up my environment bit and post a full sessionInfo() now Commented Jan 27, 2015 at 11:58
  • Full cleardown and it worked, pesky PICNIC. Commented Jan 27, 2015 at 12:04

1 Answer 1

7

To convert a reactive object in shiny to a "standard" object in R, use the function shiny::reactiveValuesToList() which changes the S6 class into a standard list object.

This can then be wrapped in as.data.frame or similar to coerce to a table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.