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

"could not find function" error in shiny app when calling ddply #282

Open
webdevdufrain opened this issue Aug 23, 2016 · 0 comments
Open

Comments

@webdevdufrain
Copy link

I'm not sure whether this is a bug / feature with Shiny or ddply, but my suspicion is the latter...

When I use ddply within a shiny app, I get an odd error where ddply cannot find a function that clearly exists. My guess is that it's something to do with the something that happens within the search path somewhere inside ddply, but I can't work it out. Here is a minimal example

library(shiny)
library(plyr)

ui <- bootstrapPage(
  numericInput('n', 'minus', 0),
  plotOutput('plot')
)

server <- function(input, output) {
  output$plot <- renderPlot({

    nn <- input$n

    meanMinus <- function(x, n) {
      mean(x) - n
    }

    print(exists('meanMinus')) ## TRUE
    i2 <- ddply(
      iris,
      .(Species),
      .fun=summarise,
      blah=meanMinus(Sepal.Length, nn)
    ) ## Error in eval: could not find function "meanMinus"

    plot(i2)
  })
}

shinyApp(ui = ui, server = server)

Just to be clear, the ddply call works perfectly outside a shiny app.
It seems to me that when calling ddply within an app it's not able to examine the environment in which it is called. Yet other functions (e.g. exists) are quite comfortable with seeing the object called meanMinus.

Can anyone offer a fix if it is a bug, or a workaround / explanation if it's a feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant