In R Shiny, How do I ensure variable value propagation within same code block in R?

Joined
Sep 29, 2022
Messages
1
Reaction score
0
Hello,

I have an input in a code block in R (Shiny) using R Studio IDE.

How do I use the value of that input within the same block, i.e. in below example; how to make sure that value of input$histPlotNumFig is used later below in the line "for (i in 1:input$histPlotNumFig) {" without the compiler giving argument length is zero error.

CODE-

output$plotHistogramsUI <- renderUI({
req(dataCache$featureNames)

allColumns <- union(dataCache$featureNames, dataCache$predTargetNames)

ctrl <- list(fluidRow(column(6, numericInput('histPlotNumFig', 'Number of plots', 1, min = 1)),
column(6, numericInput('histPlotNumFigPerRow', 'Plots per row', 3, min = 1))))

ctrl <- append(ctrl, list(selectInput('plotHistograms', label = 'Feature',
multiple = T, choices = allColumns, selected = NULL)))

dF <- dataCache$dataFrame

for (i in 1:input$histPlotNumFig) {
# reuse existing values if any
isolate({
if (is.null(input[[paste0('histPlotFeatures', i)]])) {
selected <- NULL
} else {
selected <- input[[paste0('histPlotFeatures', i)]]
}
})

numColumns <- dataCache$dataCols[sapply(dataCache$dataFrame[, dataCache$dataCols, drop = F], is.numeric)]

ctrl <- append(ctrl, list(selectizeInput(paste0('histPlotFeatures', i), label = paste0('Feature(s) - Plot ', i),
multiple = T, choices = numColumns, selected = selected)))
}

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,922
Messages
2,570,047
Members
46,475
Latest member
RacheleGri

Latest Threads

Top