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

Move shiny to Imports #529

Closed
pawelru opened this issue Jan 23, 2024 · 17 comments · Fixed by #546
Closed

Move shiny to Imports #529

pawelru opened this issue Jan 23, 2024 · 17 comments · Fixed by #546
Assignees
Labels

Comments

@pawelru
Copy link
Contributor

pawelru commented Jan 23, 2024

Depends type of dependency is generally discouraged. Would it be possible to move this to Imports instead?

@donyunardi
Copy link
Contributor

donyunardi commented Jan 23, 2024

With the current setup, we make sure that the shiny package is attached when teal.slice is attached.
Moving this doImports means that shiny will be installed but won't be attached when teal.slice is attached.

I look around the code and it looks like we always use shiny:: prefix when using shiny's function, but probably would need to be looked thoroughly.

@pawelru
Copy link
Contributor Author

pawelru commented Jan 24, 2024

For exactly this reasons we already have shiny (among others) in Depeds of teal and I see the value in there. However here, in teal.slice, I am not so sure. It's somehow redundant given what teal has. Do we see any real use case of teal.slice alone (without teal)?

@chlebowa
Copy link
Contributor

Do we see any real use case of teal.slice alone (without teal)?

I thought the intent was to allow it.

@pawelru
Copy link
Contributor Author

pawelru commented Jan 24, 2024

Right. That was an inaccurate question.
Let me share my view on this so that you can better understand my point. I personally see packages with Depends as a meta packages that tells you "load me and I will load extra pkgs that you need". teal perfectly fits into this definition as we keep telling "please just do library(teal) and that it" (or to be more precise: library(teal.modules.xyz)). It's sort of a library(tidyverse) (even though I'm not using it).
I cannot find this true for teal.slice. I see it more as a rather low-level functionalities package which load should be accompanied with additional library(shiny) call - exactly how it is in the current "Getting started" vignette.
The other thing, as I mentioned, is that Depends is discouraged:

Unless there is a good reason otherwise, you should always list packages in Imports not Depends. That’s because a good package is self-contained, and minimises changes to the global landscape, including the search path.

source

@m7pr m7pr mentioned this issue Jan 24, 2024
15 tasks
@m7pr
Copy link
Contributor

m7pr commented Jan 24, 2024

@pawelru we will need to add library(shiny) or use shiny:: as prefix in examples if we move shiny from Depends to Imports. A thing to remember when doing the transition.

@chlebowa
Copy link
Contributor

No we won't, @import shiny will cover that.

@m7pr
Copy link
Contributor

m7pr commented Jan 24, 2024

A test package https://github.com/m7pr/import_test
That only has @import shiny https://github.com/m7pr/import_test/blob/main/R/hello.R#L10
and shiny in Imports https://github.com/m7pr/import_test/blob/main/DESCRIPTION#L15
but fails on examples execution without library(shiny) nor prefixing

https://github.com/m7pr/import_test/actions/runs/7639811026/job/20813626827#step:40:107

checking examples ... ERROR
  Running examples in 'r.pkg.template-Ex.R' failed
  The error most likely occurred in:
  
  > base::assign(".ptime", proc.time(), pos = "CheckExEnv")
  > ### Name: hello
  > ### Title: Personal greeting
  > ### Aliases: hello
  > 
  > ### ** Examples
  > 
  >  isolate()
  Error in isolate() : could not find function "isolate"
  Execution halted

1 error| 0 warnings| 0 notesError: R CMD check found ERRORs
Execution halted

Exited with status 1.

@chlebowa
Copy link
Contributor

It is because they are not re-exported.

I stand corrected 👍

@m7pr
Copy link
Contributor

m7pr commented Jan 24, 2024

I'm not sure what's going on. @import shiny has nothing to do with examples execution and has no impact on them, so what was your point in here?

@m7pr
Copy link
Contributor

m7pr commented Jan 24, 2024

For now we have prefixing in examples and library(shiny) on main, so examples and vignettes will work no matter shiny is in Depends or Imports in DESCRIPTION file and I think NAMESPACE, hence @import shiny has no impact on shiny functions being used in examples. It has effect on shiny functions being used in teal.slice functions.

However this active and soon to be closed PR #506 removes prefixing and library(shiny) calls, so once this PR is merged and then shiny is moved from Depends to Imports in DESCRIPTION file, examples will not work.

@m7pr
Copy link
Contributor

m7pr commented Jan 24, 2024

So we either

  • do need to have shiny:: prefix and library(shiny) calls in examples if we have shiny in Imports (proposed in this PR)
  • do not need to have shiny:: prefix and library(shiny) calls in examples if we have shiny in Depends (current main)

@donyunardi
Copy link
Contributor

There are too many docs that we need to double check if we move this to Imports and we're too close for release.
Let's explore this after the release.

@averissimo
Copy link
Contributor

  • do need to have shiny:: prefix and library(shiny) calls in examples if we have shiny in Imports (proposed in this PR)

It might not be that big change in the option that @m7pr mentioned, granted it's 17 files that need to be touched, but there's only 1 user-facing example (FilterPanelAPI, all others are internal ones)

devtools::test(), devtools::runExamples(fresh = TRUE) and devtools::check() run fine with adding library(shiny) when needed

@m7pr
Copy link
Contributor

m7pr commented Jan 25, 2024

Yeah, we have GHA tests/flows that can verify if that transition (from Depends to Imports) and change in examples gives the proper build of the package. I assume we can just see if there is anything requiring shiny in the example of the function, and then add library(shiny) and basically that's the whole change. And you go through all examples.

@averissimo
Copy link
Contributor

these change seem to do the trick. Pushed a sandbox branch (based on the current pre-release) that can serve as the reference point when implementing this

@pawelru
Copy link
Contributor Author

pawelru commented Jan 25, 2024

Please also don't forget about vignettes (and possibly README.md)

@averissimo
Copy link
Contributor

The check function rebuilds the vignettes and they already use the library(shiny) on the relevant chunks.

Good point about the README.md, but it's super simple without any working examples (it points to the vignettes)

@chlebowa chlebowa mentioned this issue Jan 31, 2024
34 tasks
averissimo added a commit that referenced this issue Jan 31, 2024
# Pull Request

- Fixes #529

ℹ️ Note: The package imports all functions from `{shiny}` via `@import
shiny` {roxygen2} tag, however, there's a mixed bag of prefixed
(`shiny::fun(...)`) and non-prefixed calls (`fun(...)`) in the
(functions') code. ~~Those were not modified.~~ (see discussion)

#### Changes description

- Remove occurences of `shiny::` from `R/` code
- Moved `{shiny}` to Imports
- Replaced shiny functions in examples by
  - add `library(shiny)` when building a shiny app to run
  - ~~`fun` -> `shiny::fun` for others~~
- Corrects vignettes accordingly

---------

Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Aleksander Chlebowski <114988527+chlebowa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants