Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using data.table in shiny application

When I use a data table object within a shiny application I get an error.

This example is adapted from this article by Garrett Grolemund. Where the whole shiny application is packaged into one function, and rendered in an Rmd file. To reproduce, put the following code into an .Rmd file in R Studio and compile it using using ctrl-k http://shiny.rstudio.com/articles/function.html

---
runtime: shiny
output: html_document
---

```{r echo = FALSE}
binner <- function(var) {
  require(shiny)
  shinyApp(
    ui = fluidPage(
      sidebarLayout(
        sidebarPanel(sliderInput("n", "Bins", 5, 100, 20)),
        mainPanel(plotOutput("hist"),
                  htmlOutput("SessionInfo")))), 
    server = function(input, output) {
      output$hist <- renderPlot(hist(var, breaks = input$n, col = "skyblue", border = "white"))
      output$SessionInfo <- renderText(paste(capture.output(sessionInfo()), collapse="<br>"))
    }
  )
}
```
## Old Faithful

Old faithful is known for erupting at regular intervals. But how regular are these intervals?  

```{r echo = FALSE}
library(data.table)
faithful_dt <- as.data.table(faithful)
binner(faithful_dt[ , waiting])
```

When I compile, I get this error:

Shiny Error

I've seen an error like this when using data.table within a package. However that's fixed if you include data.table in the Imports or Depends declarations in the package (see FAQ 6.9 http://cran.r-project.org/web/packages/data.table/vignettes/datatable-faq.pdf)

Here is the output of sessionInfo() from inside the shiny app enter image description here

like image 410
geneorama Avatar asked Sep 16 '14 14:09

geneorama


1 Answers

This is no longer an issue as of data.table 1.9.4

like image 169
geneorama Avatar answered Oct 18 '22 07:10

geneorama