Skip to content

Commit

Permalink
fix example_module, remove deprecated teal_data() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Nov 20, 2023
1 parent 8ae9eee commit b7b6b3a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
35 changes: 20 additions & 15 deletions R/dummy_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ example_datasets <- function() { # nolint
#' @examples
#' app <- init(
#' data = teal_data(
#' dataset("IRIS", iris),
#' dataset("MTCARS", mtcars)
#' IRIS = iris,
#' MTCARS = mtcars
#' ),
#' modules = example_module()
#' )
Expand All @@ -92,27 +92,32 @@ example_module <- function(label = "example teal module", datanames = "all") {
checkmate::assert_string(label)
module(
label,
ui = function(id) {
ns <- NS(id)
teal.widgets::standard_layout(
output = dataTableOutput(ns("table")),
encoding = div(
selectInput(ns("dataname"), "Choose a dataset", choices = NULL),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
)
)
},
server = function(id, data) {
checkmate::assert_class(data, "tdata")
checkmate::assert_class(data, "reactive")
moduleServer(id, function(input, output, session) {
output$text <- renderPrint(data[[input$dataname]]())
observeEvent(data(), {
updateSelectInput(session, "dataname", choices = teal.data::datanames(data()))
})

output$table <- renderDataTable(data()[[input$dataname]])

teal.widgets::verbatim_popup_srv(
id = "rcode",
verbatim_content = attr(data, "code")(),
verbatim_content = reactive(teal.code::get_code(data())),
title = "Association Plot"
)
})
},
ui = function(id, data) {
ns <- NS(id)
teal.widgets::standard_layout(
output = verbatimTextOutput(ns("text")),
encoding = div(
selectInput(ns("dataname"), "Choose a dataset", choices = names(data)),
teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
)
)
},
datanames = datanames
)
}
Expand Down
9 changes: 3 additions & 6 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,10 @@
#' @include modules.R
#'
#' @examples
#' new_iris <- transform(iris, id = seq_len(nrow(iris)))
#' new_mtcars <- transform(mtcars, id = seq_len(nrow(mtcars)))
#'
#' app <- init(
#' data = teal_data(
#' dataset("new_iris", new_iris),
#' dataset("new_mtcars", new_mtcars),
#' new_iris = transform(iris, id = seq_len(nrow(iris))),
#' new_mtcars = transform(mtcars, id = seq_len(nrow(mtcars))),
#' code = "
#' new_iris <- transform(iris, id = seq_len(nrow(iris)))
#' new_mtcars <- transform(mtcars, id = seq_len(nrow(mtcars)))
Expand All @@ -78,7 +75,7 @@
#' "Iris Sepal.Length histogram",
#' server = function(input, output, session, data) {
#' output$hist <- renderPlot(
#' hist(data[["new_iris"]]()$Sepal.Length)
#' hist(data()[["new_iris"]]$Sepal.Length)
#' )
#' },
#' ui = function(id, ...) {
Expand Down
4 changes: 2 additions & 2 deletions R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' library(shiny)
#'
#' app <- init(
#' data = teal_data(dataset("iris", iris)),
#' data = teal_data(iris = iris),
#' modules = modules(
#' label = "Modules",
#' modules(
Expand Down Expand Up @@ -199,7 +199,7 @@ is_arg_used <- function(modules, arg) {
#' library(shiny)
#'
#' app <- init(
#' data = teal_data(dataset("iris", iris)),
#' data = teal_data(iris = iris),
#' modules = list(
#' module(
#' label = "Module",
Expand Down
4 changes: 2 additions & 2 deletions man/example_module.Rd

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

9 changes: 3 additions & 6 deletions man/init.Rd

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

2 changes: 1 addition & 1 deletion man/module.Rd

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

2 changes: 1 addition & 1 deletion man/modules.Rd

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

0 comments on commit b7b6b3a

Please sign in to comment.