Closed raubreywhite closed 7 years ago
It works in a normal Shiny app, so this is probably specific to Shiny + Rmd documents:
library(data.table)
library(shiny)
shinyApp(
ui = fluidPage(
tableOutput("tbl")
),
server = function(input, output) {
getData <- reactive({
data <- data.table(x=1:10,y=1:10)
data[x==1]
})
output$tbl <- renderTable({
getData()
})
}
)
Interesting... Do you have any suggestions on where I should repost it? flexdashboard, probably?
Here's a a simplified Rmd example that gives the same error, object 'x' not found
:
---
title: "data.table test"
runtime: shiny
---
```{r}
library(data.table)
library(shiny)
getData <- reactive({
data <- data.table(x=1:10, y=1:10)
data[x==1]
})
```
```{r}
renderTable(getData())
```
```{r}
renderPrint({
str(getData())
})
```
```{r}
# This works OK
data2 <- data.table(x=1:10, y=1:10)
data2[x==1]
```
I think there's probably some issue with the non-standard evaluation of the code in the reactive. For some reason it happens only with a Shiny doc, but not in a regular Shiny app.
Thanks for reporting. Should be resolved now. Please test and close. https://github.com/Rdatatable/data.table/wiki/Installation#install-datatable-development-version
Looks like it works!
This has been brought up in data.table as well (https://github.com/Rdatatable/data.table/issues/2001)
These examples all use this framework: http://rmarkdown.rstudio.com/flexdashboard/
So you need to rename "failingFlexdashboard.txt" to "failingFlexdashboard.Rmd" and then you can run it (the same with "workingFlexdashboard.txt" -> "workingFlexdashboard.Rmd").
I've also attached the log from my shiny server that gives the error.
Basically, when the reactive data contains a data.table instance, it fails. When the reactive data contains a data.frame instance, it works.
test_error-docker-20170508-120846-37265 (linux's conflicted copy 2017-05-08) (linux's conflicted copy 2017-05-08) copy.txt failingFlexdashboard.txt workingFlexdashboard.txt Basically, Shiny seems to be trying to treat it as a data.frame, not a data.table, so it can't find the variable to stratify on.