1

TL;DR

How do I reference/use a local package function from the shiny app that I am running, when it is not in my win-library?

ERROR:

Warning: Error in : there is no package called 'humblFinance'

PSEUDO-CODE:

 output$p1 <- renderPlot({

            future::future({
            out   <- myPackage::collect_price(symbol = input$tickerInput,
                                                 range = "1m")
            input <- input
                out   <- out %>%
                    ggplot2::ggplot(ggplot2::aes(x = date, y = fclose)) +
                    ggplot2::geom_line(size = 1) +
                    ggplot2::labs(title = glue::glue("{input$tickerInput} Price Chart"), y = "Closing Price", x = "")
                return(out)
            }) %...>% (
                function(result){ return(result) }
            ) %...!% (
                function(error){ warning(error) }
            )
        })

I am getting the error below when trying to use a function mypackage::myfun() in a future({}) statement. my shinyApp is creating with the golem and brochure infrastructure, so I am not sure where to reference this package? I have tried installing the package within the statement but doesn't seem to work. Should I point the future call to the tarball in the project root directory?

  1. loadNamespace() didnt work
  2. attatchNamespace() didnt work
  3. remotes::install_local() didnt work
JJ Fantini
  • 213
  • 1
  • 11
  • 1
    Where is the package? Usually you would install packages before calling code that uses them, not in a `renderPlot` function that would try to install the package every time the plot is updated. – Gregor Thomas Sep 19 '22 at 15:32
  • @GregorThomas the package is created in the `golem` infrastructure of the shinyApp, so it is a local package, not installed from cran nor github...should I direct `future` to use the tarball? – JJ Fantini Sep 19 '22 at 15:57
  • 1
    Sorry, I haven't used golem at all, but at a glance your golem app is an R package. Best case, you put your package in the NAMESPACE file and treat it as a normal dependency. If you can't do that... well maybe make sure the package is installed **when the app starts**, and if not install it from the tarball then--not inside a `render` function, and definitely not inside a `future` function. – Gregor Thomas Sep 19 '22 at 16:09
  • yeah @GregorThomas , not sure how to put a packages own name in it NAMESPACE itself, would I need to use `UseDynLib()` to achieve this? Pakage is installed when the app starts as well – JJ Fantini Sep 19 '22 at 16:37
  • So, `humblFinance` is the name of the golem package?? Then you shouldn't use `humblFinance::` at all inside the package. Your question makes it seem like you are talking about a different package. (Well, since your question doesn't mention `golem` at all it doesn't seem like you're working with a golem package...). You certainly don't want a package to try to install itself... that doesn't make any sense. But you will need to install the package to run it. – Gregor Thomas Sep 19 '22 at 16:55
  • Yes, `humblFinance` is the name of the package...doesnt seem to work when I dont reference the package...will work on getting a reprex error going – JJ Fantini Sep 20 '22 at 14:21

1 Answers1

0

Have you tried the answer in this post:

I get an error when using {future} and {furrr} functions within a Golem Shiny App, what does it come from?

This solution hasn't worked for me but seems to have worked for the author of the post

LeeRoyAus
  • 21
  • 2