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

[Question]: Support in shinyframewroks vscode extension #1455

Open
3 tasks done
davidrsch opened this issue Jan 20, 2025 · 7 comments
Open
3 tasks done

[Question]: Support in shinyframewroks vscode extension #1455

davidrsch opened this issue Jan 20, 2025 · 7 comments
Labels
question Further information is requested

Comments

@davidrsch
Copy link

What is your question?

Hello,

I am working on a VSCode extension that aims to bring some of the capabilities of RStudio addins to Shiny developers using VSCode and Positron. You can check it out on the repository, VSCode Marketplace, and Open VSX Registry.

The extension currently supports several R frameworks:

  • basic shiny
  • rhino
  • golem

I would like to expand support to include teal, leprechaun, and some Python frameworks like tapyr. If you know of any other frameworks that should be added, please let me know!

Regarding teal, I haven’t worked with this framework before, so your help would be greatly appreciated. The extension offers three main features: "Create App", "Create Module", and "Addins". It would be helpful if you could point me to resources or documentation on how to implement "Create App" and "Create Module" for this framework, and share any suggestions on which features should be included under "Addins".

Thank you for your time and assistance!

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
@davidrsch davidrsch added the question Further information is requested label Jan 20, 2025
@gogonzo
Copy link
Contributor

gogonzo commented Jan 20, 2025

I like the idea @davidrsch. All resources are in teal's documentation page. There are links which might redirect you to other related packages. What do you envision? Sort of a visual manager or providing code snippets/suggestions?

@davidrsch
Copy link
Author

The extension functions as a visual manager, making it easy (just two or three clicks) for developers to perform actions like creating an app, adding modules, or executing certain features.

From the examples I’ve seen, teal apps are often contained within a single app.R file, which requires in-file modifications—a functionality I haven’t implemented yet. It would be extremely helpful if you could clarify what each action should do or point me to any existing functionality that achieves a similar result:

  • "Create App": This should generate an app.R file containing a comprehensive example app definition (as complete as possible).
  • "Create Module": This should modify the existing app.R file by adding a new module definition (also as complete as possible).

@gogonzo
Copy link
Contributor

gogonzo commented Jan 20, 2025

point me to any existing functionality that achieves a similar result:

To create a teal app you need to have a list of modules you'd like to use within an app. Probably you don't want to "Create a module" but "add a module" from some list. To create a module, you'd need to write ui and server functions just like you do with normal shiny module. This is why I think you prefer to start with "add a module" to include for example tm_data_table() to your init(modules = modules(...)) call.

@davidrsch
Copy link
Author

Do you, by any chance, have defined standards for organizing teal apps in a modularized format using multiple files? Something similar to:

> renv  
> tests  
⌄ app  
  ⌄ modules  
    module_1.R  
  modules.R  
.Rprofile  
README.md  
app.R  
renv.lock

With this structure, the "Create App" functionality would generate the folder layout and initial files, while "Add Module" would create a new module_X.R file inside the app/modules/ directory.

If no such standard exists, I think the example shown in the teal module documentation could be a good starting point to define the features for adding modules and structuring apps.

@gogonzo
Copy link
Contributor

gogonzo commented Jan 20, 2025

@davidrsch This is an interesting idea worth consideration (to have an teal::init function based on the files structure). Teal limitation doesn't stop you from building app.R always containing following lines

teal::init(
  data = source("data.R"),
  modules = source("modules.R"),
  filter = source("filter.R")
) |> shiny::runApp()

Where data.R

library(teal.code)
teal_data() |> eval_code(readLines("path/to/script/with/data.R")) 

modules.R

do.call(
  teal::modules, 
  lapply(list.files(path = "modules/", pattern = "\\.R$"), source) # file is expected to return a module
)

@davidrsch
Copy link
Author

If it’s okay with you, for now, I’ll proceed with implementing the functionalities using the single-file approach. The goal of the extension is to assist Shiny developers in working with the framework while adhering to the current standards, making it useful for both new and experienced users who may be more familiar with this format. If, after consideration, you decide to introduce standards for a multiple-file structure, I’d be happy to update the extension to support it.

@davidrsch
Copy link
Author

Example content for the app.R file that would be created when executing the "Create App" action:

library(shiny)

# Define modules
module_1 <- module(
  label = "a module",
  server = function(id, data) {
    moduleServer(
      id,
      module = function(input, output, session) {
        # module_1 server content
      }
    )
  },
  ui = function(id) {
    ns <- NS(id)
    # module_1 ui content
  },
  datanames = "all"
)

module_2 <- module(
  label = "another module",
  server = function(id) {
    moduleServer(
      id,
      module = function(input, output, session) {
        # module_2 server content
      }
    )
  },
  ui = function(id) {
    ns <- NS(id)
    # module_2 ui content
  },
  datanames = NULL
)

# Define modules' structure
modules <- modules(
  label = "modules",
  modules(
    label = "nested modules",
    module_1
  ),
  module_2
)

# Define filters
filter_1 <- teal_slice(
  # dataname = ,
  # varname = 
)

filter_2 <- teal_slice(
  # dataname = ,
  # varname = 
)

filters <- teal_slices(
  filter_1,
  filter_2
)

# Initialize app
app <- init(
  data = teal_data(),
  modules = modules,
  filter = filters,
  title = "My app",
  header = tags$h1("My app"),
  footer = tags$p("By me")
)

shinyApp(app$ui, app$server)

Any suggestions to make it more comprehensive are welcome!

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

No branches or pull requests

2 participants