-
-
Notifications
You must be signed in to change notification settings - Fork 3
WIP: POC Redesign extraction #256
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
Conversation
This would specify "factor columns from |
Yes, I'm glad it is easy to understand.
Not sure I fully understand your question. Variables can also be manually set, for example
The only limitation is that the function provided should return a logical vector. In terms of implementation, the function is applied to the names and to the values, precisely to accommodate cases like this. |
I don't get this one. I would think it would return columns where the values are in all caps. |
The same function is applied to column names and column values? 🤔 |
It could mean both things imho. But here it is specifying variables, not values. For filtering by value there is td <- within(teal.data::teal_data(), {
df <- data.frame(A = as.factor(letters[1:5]), Ab = letters[1:5])
m <- matrix()
})
spec <- datasets("df") & variables(function(x){x==toupper(x)})
resolver(spec, td) Still selects A as the name is in capital letters
Yes, if there is a single argument that should accept |
Thanks, it does explain things a bit. |
I updated the branch to make it easy to reflect updates on selections from the possible choices. Besides some internal functions, it now exports a new key function Here is a full example with a shiny module and teal: library("teal")
library("shiny")
# Initialize the teal app
mod <- function(label, x, y) {
module(
ui = function(id, x, y) {
ns <- NS(id)
div(
module_input_ui(ns("x"), "x", x),
module_input_ui(ns("y"), "y", y),
shiny::tagList(
shiny::textOutput(ns("text"))
)
)
},
server = function(id, data, x, y) {
moduleServer(id, function(input, output, session) {
x_in <- module_input_server("x", x, data)
y_in <- module_input_server("y", y, data)
output$text <- shiny::renderText({
req(x_in(), y_in())
l <- lapply(
list(x = x_in, y = y_in),
function(sel) {
if (sum(lengths(sel()))) {
paste0(
"Object: ", sel()$datasets, "\nVariables: ",
paste0(sel()$variables, collapse = ", ")
)
} else {
"No info??"
}
}
)
unlist(l)
})
})
},
ui_args = list(x = x, y = y),
server_args = list(x = x, y = y)
)
} Here I create three different specifications, you can pass them to the app and they will work: iris_numeric <- datasets("IRIS") & variables(is.numeric)
mtcars_char <- datasets("MTCARS") & variables(is.character)
iris_numeric_or_mtcars_char <- iris_numeric | mtcars_char
app <- init(
data = teal.data::teal_data(IRIS = iris, MTCARS = mtcars),
modules = modules(
mod(x = datasets("IRIS") & variables(is.factor),
y = datasets("MTCARS") & variables(is.numeric))
)
)
shinyApp(app$ui, app$server) |
Short summary about the discussion we had regarding selection based on the possible choices and how to select them. We decided to keep the tidyselect on the selection but only pass the possible choices. A small example for the extraction of the factors variables but selecting those without NAs: devtools::load_all(".")
td <- within(teal.data::teal_data(), {
i <- iris
p <- penguins
m <- diag(5)
})
r <- resolver(c(datasets(where(is.data.frame), "p"),
variables(where(is.factor),
!where(anyNA))),
td)
r$variables$select
## "species" "island" We don't need to repeat the initial code for selecting the variables and tidyselection makes it flexible for multiple use cases (for example avoid plotting with NAs or outliers even if they are valid numeric or categorical values). |
- input module reactivity works - merge works for data.frames - inputs minimized to badge-pill
- use labels in input when possible
cfcb269
to
3ec348b
Compare
Closing a PR and opening NEW soon to have a clean discussion feed |
Linked to insightsengineering/NEST-roadmap#36
Pull Request
Redesign extraction
This branch/PR is a POC of specification of user input to be extracted.
See tests added about how it works (currently most if not all of them should work), but simple example of specification:
Features:
Examples
Resolve input to be used by module developer
The
module_input_ui
andmodule_input_server
help the developer to get the required data.Merge arbitrary data
The
merge_module_srv
accepts the inputs and merge arbitrary data processed by themodule_input_server
, this is done thanks toextract_input
the responsible to obtain the requested data fromdata()
.MAE
DONE
TODO 1
Only up to the server body, check the defaults,
8 hours each module, mmrm = 10 hours.
If there's no bug, then this is the checkpoint of the stable feature branch.
TODO 2
20 hours
resolver()
is good enough? Is it simple to create the code for reproducibility withteal_data
inside the module viaextract()
?datasets(select = )
,variables(select = )
,values(select = )
.What should be the constructor of the modules should have as a default for the extract spec (i.e. is it data.frame? take all numeric columns? Only select the first one (with all available options)?
Each module might have different requirements.