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:
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
This is no longer an issue as of data.table 1.9.4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With