-
Notifications
You must be signed in to change notification settings - Fork 173
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 use dbplyr in a shiny app #439
Comments
You'll need to use |
I think this is something that should be mentioned explicitly in documentation regarding shiny. There is a lot of documentation from RStudio regarding using dplyr for running SQL queries and for using SQL in shiny apps, but there is 0 mentions that they don't work together. It's not intuitive behaviour. I understand your point as to why it doesn't work, but most shiny users would expect this to just work. |
They do work together; you just need to tell dbplyr that you want it to evaluate the functions locally, not on the database like all the other functions that your expecting to be translated. |
Yes I do understand that. But if you look at it from a typical user's perspective: When doing an analysis interactively, they would use
Then when placing this inside a shiny app, it's extremely natural (and good practice) to simply replace any variables with reactives. So that would become
But this results in an error. And a non-useful confusing error too. I really believe this should be clearly documented for shiny usage. The default behaviour shiny users will try to do does not work and there is no documentation or useful error messages as to why. The normal shiny user doesn't understand the technical details of what dbplyr expects and how it's different than using regular dplyr. |
@daattali am I right that you started using dplyr with database backends yesterday? It might be worth spending a bit more time with the framework to get a sense of what's tricky about this issue, and why it's sort of hard to warn or evaluate the function. Importantly I think you might be atypical in amount of time you've spent with shiny relative to dbplyr. I think most people probably use a database backend inside of, or in reference to, other functions before using it with shiny which makes things a bit more intuitive. You have to be explicit with what you want to translate to the database whenever you're using a DB backend inside of, or in reference to, other functions. An example is below. The way I think of it is that
Another example is the following, what would you expect to happen here?
|
Thanks for the thorough comments @gshotwell That all makes sense, it's very useful, really. However, I don't think this negates my point that shiny developers don't need to understand these technical details. In an ideal world, yes, this would be a non issue, but in practice people just take their code and put it inside shiny, and replace variables with reactives. It works in any other context. It's ok if it doesn't work here, but I don't see why there's pushback re: documenting it and warning shiny users (I don't mean warning during runtime, I mean warning in docs). As further proof of how intuitive it is for shiny devs to try this, look at this page on RStudio's website describing how to use dplyr+databases in shiny. The code there no longer works because of this issue. In that code they use I almost always say in github issues that "I don't feel too strongly - you're the dev so obviously it's your call". But in this case, I do feel very strongly that the fact that dplyr doesn't just "work" in shiny when using databases must be documented. |
As game designer using R and shiny as dashboard to analyse games I work on, I can share my 'noob level' experience.
This wasn't the end of the world... In retrospect i should have made the mental connection that I had to force local evaluation, after all you quickly need to grasp that concept when using Shiny.
So as a noob level user I do support @daattali that it warrants a mention on the DBI article for Shiny 👍 I'm a big fan and promoter of R/Shiny in video games over the likes of Tableau / GA...huge thank for all the work, such a joy to use and see tools mature. |
I've made this an error to be consistent with using (e.g.) |
I just tried it, and yes it's much more helpful now, thanks |
Below is a simple reprex
It produces an error
no such function: my_speed
. It looks like dbplyr thinks that my reactive is a database table? 😕 Note that if I save the reactive value to a local variable earlier and use that variable, then it does work. But it seems strange that I won't be able to use reactives in my sql, and I couldn't find any documentation suggesting this is expected.The text was updated successfully, but these errors were encountered: