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

Custom functions not found when using future/furrr packages #921

Open
leeroyaus opened this issue Sep 28, 2022 · 0 comments
Open

Custom functions not found when using future/furrr packages #921

leeroyaus opened this issue Sep 28, 2022 · 0 comments

Comments

@leeroyaus
Copy link

I'm trying to use custom functions stored in the utils_helper.R file in a golem Shiny App with packages like future/furrr/rmarkdown but the custom functions can't be found.

When using custom function with future/furrr packages, the error message is:
Error: there is no package called 'packageName'
where packageName is the name of the golem Shiny App.

An example of this is below:

app_ui

#' The application User-Interface
#'
#' @param request Internal parameter for `{shiny}`.
#'     DO NOT REMOVE.
#' @import shiny
#' @noRd
app_ui <- function(request) {
  tagList(
    # Leave this function for adding external resources
    golem_add_external_resources(),
    # Your application UI logic
    fluidPage(
      plotOutput("plot")
    )
  )
}

#' Add external Resources to the Application
#'
#' This function is internally used to add external
#' resources inside the Shiny application.
#'
#' @import shiny
#' @importFrom golem add_resource_path activate_js favicon bundle_resources
#' @noRd
golem_add_external_resources <- function() {
  add_resource_path(
    "www",
    app_sys("app/www")
  )

  tags$head(
    favicon(),
    bundle_resources(
      path = app_sys("app/www"),
      app_title = "renderRmd.shinyapps.io"
    )
    # Add here other external resources
    # for example, you can add shinyalert::useShinyalert()
  )
}

app_server.R

#' The application server-side
#'
#' @param input,output,session Internal parameters for {shiny}.
#'     DO NOT REMOVE.
#' @import shiny progressr future furrr
#' @noRd
app_server <- function(input, output, session) {
  output$plot <- renderPlot({
    X <- 1:24
    plan(multisession(workers = 6))

    future({
      msgFunc()
    })

    withProgressShiny(message = "Calculation in progress",
                      detail = "This may take a while ...", value = 0, {
                        p <- progressor(along = X)
                        y <- future_map(X, function(x) {
                          Sys.sleep(1)
                          msgFunc(x) #If comment out this line, the app works
                          p()
                        })
                      })
    plot(cars)
  })
}

utils_helper.R

#' helpers
#'
#' @description A utils function
#'
#' @return The return value, if any, from executing the utility.
#'
#' @noRd

msgFunc <- function(x){
  print(
    paste(
      "Calculating",
      x
    )
  )
}

@ColinFay provided a solution (used above) but this isn't working for me

I also tried using a similar solution when rendering an Rmd file that used custom functions, but this also didn't work

Thanks for the assistance

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