-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Fix outliers module #277
Fix outliers module #277
Conversation
Code Coverage Summary
Results for commit: 5e008f64f3f876551d20b2c9500b40440b5c643d Minimum allowed coverage is ♻️ This comment has been updated with latest results |
The error occurs here https://github.com/insightsengineering/teal.devel/blob/1750c9d4d5068edc94d0426617662226c2dc8ee9/R/merge_datasets.R#L50. I am investigating further. |
The problem is here https://github.com/insightsengineering/teal.devel/blob/1750c9d4d5068edc94d0426617662226c2dc8ee9/R/data_extract_module.R#L394-L407. For sure is not in the scope of this PR. |
@mhallal1 here we have a problem with merge module/ data extract. Looks to be a global problem. |
I am finally sure what is the problem. |
Good spot! |
inputs should be available from the first line of code in server like here (example shiny app):
However when we use insertUI (even with immediate option) with shiny inputs then we have to wait for second reactive cycle to see inputs added by insertUI. #
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
div(id = "input22")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
insertUI("#input22", immediate = TRUE, ui = textInput(session$ns("xx"), "xx", "xxx"))
output$distPlot <- renderPlot({
## input xx visible in the second reactive cycle.
browser()
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server) |
Looks like this https://github.com/insightsengineering/teal/blob/1ae9092332afe97b4159a3ed609681c8796a4b81/R/module_teal_with_splash.R#L60-L70 then we could resolve ddl args on ui level and insertUI will not be needed? |
Still not sure why this works. Custom module is "inserted" by the teal and input is available immediately. No req's no validation. library(teal)
library(scda)
ADSL <- synthetic_cdisc_data("latest")$adsl
app <- init(
data = cdisc_data(cdisc_dataset("ADSL", ADSL)),
modules = root_modules(
module(
label = "test1",
filters = "all",
ui = function(id, ...) {
ns <- NS(id)
standard_layout(
encoding = sliderInput(ns("bins"), "Number of bins:", min = 1, max = 50, value = 30),
output = white_small_well(plotOutput(ns("plot")))
)
},
server = function(input, output, session, datasets) {
output$plot <- renderPlot({
cat("\ninput$bins is:", input$bins)
x <- datasets$get_data("ADSL")$BMRKR1
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
)
)
)
runApp(app) Console output
|
@gogonzo if we put cat 2 lines higher you will see the problem. ...
server = function(input, output, session, datasets) {
cat("\ninput$bins is:", input$bins)
output$plot <- renderPlot({
... in normal/regular server function input is visible from 1 line of server function, here is not. |
Yes, you are right. The bounty is not, how to render modules without insertUI but simply by calling modules (their ui and server). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussion with @pawelru , I give the approve. I will create a separate issue concerning the teal problem.
Closes #255 - also fixes a bug where app crashed if the
categorical_var
is not specifiedTest on vignette, example in the issue and also test by not specifying
categorical_var
For some reason the merge was being triggered on load (and when user deselects the dataset) whilst selector_list()$outlier_var was NULL.
I wonder if there are any other places in the code base this will affect - e.g. when having a list of
data_extract_spec
in a singledata_extract_ui
and deselecting the dataset?@mhallal1, @gogonzo I don't really understand what's happening here and maybe there should be a fix in teal.devel instead of the band-aid here?