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

Example skeleton project - DO NOT MERGE #701

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Collate:
'module_teal.R'
'module_teal_with_splash.R'
'modules_debugging.R'
'project_skeleton.R'
'reporter_previewer_module.R'
'show_rcode_modal.R'
'teal.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export(init)
export(log_app_usage)
export(module)
export(modules)
export(project_skeleton)
export(reporter_previewer_module)
export(root_modules)
export(show_rcode_modal)
Expand Down
61 changes: 61 additions & 0 deletions R/project_skeleton.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#' This function will be called when the user invokes
#' the New Project wizard using the project template defined in the template file
#' at:
#'
#' inst/rstudio/templates/project/teal_application.dcf
#'
#' It is exported so that projects can be created outside of the RStudio IDE
#'
#' @export
project_skeleton <- function(path, use_cdisc = TRUE) {

# ensure path exists
dir.create(path, recursive = TRUE, showWarnings = FALSE)

contents <- if (use_cdisc) {
'
library(teal)
library(scda)

adsl <- scda::synthetic_cdisc_data("latest")$adsl
adtte <- scda::synthetic_cdisc_data("latest")$adtte

# create data
data <- cdisc_data(
cdisc_dataset("ADSL", adsl),
cdisc_dataset("ADTTE", adtte)
)'
} else {
'
library(teal)

# create data
data <- teal_data(
dataset("IRIS", iris),
dataset("MTCARS", mtcars)
)'
}

contents <- paste(contents,
"# create modules
modules <- modules(
example_module()
)

# create app
app <- init(
data = data,
modules = modules
)

# run
shinyApp(app$ui, app$server)
",
sep = "\n"
)

contents <- styler::style_text(contents)

# write to index file
writeLines(contents, con = file.path(path, "app.R"))
}
Binary file added inst/rstudio/templates/project/teal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions inst/rstudio/templates/project/teal_application.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Binding: project_skeleton
Title: Teal Application
OpenFiles: app.R
Icon: teal.png

Parameter: use_cdisc
Widget: CheckboxInput
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(in the future) Can the Widget be for example?

Widget: availableModulesInput

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can only have the following:

image

We may want an addin to do the add modules part rather than at this project creation time. And for creating your own custom modules you could maybe? use snippets

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is snippet a Rstudio-exclusive feature?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think snippet is RStudio exclusive feature (i.e. you can add code snippet on vscode too). However, the syntax will different.

Label: Use CDISC data
Default: On
16 changes: 16 additions & 0 deletions man/project_skeleton.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.