It's most likely not related to reactives inside reactives but current input and/or ds() states.
Have you tried debugging input$inVar, input$inVar1 and ds() in a similar way as suggested yesterday - How to get the statistical summary of a reaactive dataset - #2 by margusl - adding few observers to track reactive values?
server <- function(input, output, session) {
...
observe( str(ds()) )
observe({
print("input$inVar:")
str(input$inVar)
})
observe({
print("input$inVar1:")
str(input$inVar1)
})
...
}
It would help others to help you if you'd share bit more of your app, for example we do not really know what UI controls are you using for inputs ( input$inVar* ) or how and when is ds() invalidated.
It would be ideal if you could include a minimal reproducible example that includes a complete yet minimal runnable Shiny app (including ui & server objects, all required libraries), just enough for others to reproduce your issue.
For what it's worth, a more or less minimal (though working) example could look something like this:
library(shiny)
library(bslib)
ds_lst <- list(mtcars = mtcars, iris = iris)
ui <- page_sidebar(
sidebar = sidebar(
selectInput("ds", "Dataset", choices = names(ds_lst)),
varSelectInput("var1", "Response", mtcars),
varSelectInput("var2", "Regressor", mtcars),
actionButton("fit", "Fit")
),
card(verbatimTextOutput("txt"))
)
server <- function(input, output, session) {
ds <- reactive(ds_lst[[input$ds]])
# use action button to trigger model update
model <- eventReactive(input$fit, {
# varSelectInput returns symbols, so we can use those directly with
# rlang::new_formula()
f_ <- rlang::new_formula(input$var1, input$var2)
m_ <- lm(formula = f_, data = ds())
m_$call$formula <- f_
m_
})
observe({
# update select inputs when ds() changes
updateVarSelectInput(session, "var1", data = ds())
updateVarSelectInput(session, "var2", data = ds())
})
output$txt <- renderPrint(summary(model()))
}
shinyApp(ui, server)
Screen rec
