- 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
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