Reputation: 2513
I am learning/playing/modifying Winston's great movie explorer in the shiny gallery.
Here is his server.ui code. https://github.com/wch/movies/blob/master/server.R
In his example, he used simple numeric slider range filtering for numeric movie data.
That was followed with text filtering, and this is where I run into error.
He used text input, (textInput http://shiny.rstudio.com/gallery/widgets-gallery.html)
I run into error attempting to filter (possibly multiple) text values from a list with a select box, (selectInput http://shiny.rstudio.com/gallery/widgets-gallery.html).
# Optional: filter by director
if (!is.null(input$director) && input$director != "") {
director <- paste0("%", input$director, "%")
m <- m %>% filter(Director %like% director)
}
Attempting to implement his director filter code identically, other than supplying "director" via a select box (rather than textInput), RStudio responds with...
Error in filter_impl(.data, dots(...), environment()) :
could not find function "%like%"
After much digging I believe that though it wasn't mentioned, I also may need the library(data.table) installed.
After installing and loading data.table, the error now changes to
Warning in min(x) : no non-missing arguments to min; returning Inf
Warning in max(x) : no non-missing arguments to max; returning -Inf
Warning in min(x) : no non-missing arguments to min; returning Inf
Warning in max(x) : no non-missing arguments to max; returning -Inf
Error in fdata[1, 1] : incorrect number of dimensions
I believe the warnings (not errors) refer to ggvis,
The fdata error is occurs on line 61 of his server.r code
m <- as.data.frame(m)
And this is where I find myself completely at a loss as for how to proceed.
The solution would either include an arguably superior method of filtering, or help me put the wheels back on this example's wagon.
Thank you for your time.
Oh my goodness! I am stunned by the rapid responses, they were responding before the full question was clearly typed. I am importing a CSV rather than using the SQL tie in. All 4 librarys are loaded.
Upvotes: 0
Views: 2137
Reputation: 206167
As I thought, this does seem to be specific to using RSQLite
. Here's an example
library(dplyr)
library(RSQLite)
#sample data
dd<-data.frame(name=letters[1:5], age=21:25)
dd %>% filter(age==25)
# name age
# 1 e 25
dd %>% filter(name %like% a)
# Error in filter_impl(.data, dots(...), environment()) :
# could not find function "%like%"
But now let's create a test sqlite database.
#sample sqlite database
sqlite <- dbDriver("SQLite")
exampledb <- dbConnect(sqlite,"hello.db")
dbWriteTable(exampledb, "people", dd)
sqliteCloseConnection(exampledb)
sqliteCloseDriver(sqlite)
and now we will use dplyr
to filter again
db <- src_sqlite("hello.db", create=F)
nm <- tbl(db, "people")
nm %>% filter(age==25)
# row_names name age
# 1 5 e 25
nm %>% filter(name %like% a)
# row_names name age
# 1 1 a 21
And it works. Do %like%
isn't a proper R infix operator. It's simply a command that gets escaped and translated when using a SQL connection to the appropriate SQL command.
Upvotes: 2