Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access reactiveValues in dplyr commands with sqlite #318

Closed
wch opened this issue Mar 12, 2014 · 7 comments
Closed

Can't access reactiveValues in dplyr commands with sqlite #318

wch opened this issue Mar 12, 2014 · 7 comments
Milestone

Comments

@wch
Copy link
Member

@wch wch commented Mar 12, 2014

When using dplyr in a Shiny app, it's not possible to access input$xx within dplyr functions like filter(). Example:

# Create data
library(shiny)
library(dplyr)
dat1 <- read.table(header=TRUE, text='
 id  A    B
  1  x  foo
  2  y  foo
  3  x  bar
')

vals <- reactiveValues(n = 2)

# With tbl_df, can access vals$n
d1 <- tbl_df(dat1)
r <- reactive(d1 %.% filter(id >= vals$n))
isolate(r())
# OK


# With sqlite, accessing vals$n results in error
db <- src_sqlite("test.db")
t1 <- copy_to(db, dat1)

r2 <- reactive(t1 %.% filter(id >= vals$n))
isolate(r2())
# Error in UseMethod("escape") : 
#   no applicable method for 'escape' applied to an object of class "reactivevalues"
# Error in UseMethod("escape") : 
#   no applicable method for 'escape' applied to an object of class "reactivevalues"
@hadley hadley added this to the v0.2 milestone Mar 17, 2014
@hadley
Copy link
Member

@hadley hadley commented Mar 17, 2014

What if you do r2 <- reactive(t1 %.% filter(id >= local(vals$n)))?

@wch
Copy link
Member Author

@wch wch commented Mar 17, 2014

Looks like it works with the local().

@hadley
Copy link
Member

@hadley hadley commented Mar 17, 2014

I'm going to close this for now - I think doing it automatically will be very hard.

@hadley hadley closed this Mar 17, 2014
@wch
Copy link
Member Author

@wch wch commented Mar 17, 2014

How should users know when they have to use local and when they don't?

@hadley
Copy link
Member

@hadley hadley commented Mar 17, 2014

I think any time you use $ you'll also need to use local. But maybe that implies we can do it automatically.

@hadley hadley reopened this Mar 17, 2014
@hadley
Copy link
Member

@hadley hadley commented Mar 19, 2014

Simpler reproducible example:

translate_sql(id >= vals$n, tbl = t1)

@hadley
Copy link
Member

@hadley hadley commented Mar 19, 2014

Even simpler example: partial_eval(quote(id >= vals$n), t1)

@hadley hadley closed this in 57741a8 Mar 19, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants