Error message in observer(updateVarSelectInput - attempt o select less than one elemen in get1Index

Evryhing works fine in this script except for Observe(updateVarSelectInput) . I guet the error: "Warning: Error in [[: attempt to select less than one element in get1index". This error only happens while trying to create a shiny rmarkdown document, but it does not happen in the original application. I know that it refers to to index of a list or dataframe, but I cannot figure out what the index should be.

title: "Project"
author: "Giuseppa Cefalu"
date: "2026-08-24"
output: html_document
runtime: shiny

knitr::opts_chunk$set(echo = TRUE)

Libraries

suppressMessages(suppressWarnings(library(shiny)))
suppressMessages(suppressWarnings(library(dplyr)))

Data

datasets <- list(Formaldehyde = Formaldehyde, Indometh = Indometh, LifeCycleSavings = LifeCycleSavings,
                 OrchardSprays = OrchardSprays, Theoph = Theoph, chickwts = chickwts,faithful = faithful, randu =                   randu,ChickWeight = ChickWeight, Loblolly = Loblolly,anscombe = anscombe, beaver1 = beaver1, nottem = nottem, stackloss = stackloss, swiss = swiss, DNase = DNase, Nile = Nile, 
mtcars = mtcars, trees = trees)

Create GUI

The first part of the GUI displays the project's name and a list of radiobutons, each one wih a data set name to select the data set on which the statistics will be done. The user must select a data set.

  # Create project's title panel 
  titlePanel(tags$h2("STATISTICAL ANALYSIS AND LINEARITY FOR R DATA SETS", style = "color: blue;"))

Reactive Expression:

A reactive expression is an R expression that takes user gui input and returns a value. The reactive expression will update this value whenever the original input changes. THis is where he user selects a data set name from he radiobuttons list. If he user selecs a different data set, this expression will update the value.

 # Create radio buttons list of data set names to select data set          
  radioButtons("inDs", "Select dataset:", choices = names(datasets))
 # reactive expressions update when the input changes.
  ds <- reactive( datasets[[input$inDs]] )
 varSelectInput("inVar", "Select variable:", datasets[[1]])
#reexcute when the input updates
 observe(updateVarSelectInput(session, "inVar", data = ds()))

I have made some changes to the script, and it works. It produces the effect that I was expecting, however, I get a large message after the fact that I do not understand, and the exexution halts. PLease see below


title: "Project"
author: "Giuseppa Cefalu"
date: "2026-08-24"
output: html_document
runtime: shiny

knitr::opts_chunk$set(echo = TRUE)

Libraries

suppressMessages(suppressWarnings(library(shiny)))
suppressMessages(suppressWarnings(library(dplyr)))
suppressMessages(suppressWarnings(library(shinyPredict)))

Data

datasets <- list(Formaldehyde = Formaldehyde, Indometh = Indometh, LifeCycleSavings = LifeCycleSavings,
                 OrchardSprays = OrchardSprays, Theoph = Theoph, chickwts = chickwts,faithful = faithful, randu =                   randu,ChickWeight = ChickWeight, Loblolly = Loblolly,anscombe = anscombe, beaver1 = beaver1, nottem = nottem, stackloss = stackloss, swiss = swiss, DNase = DNase, Nile = Nile, 
mtcars = mtcars, trees = trees)

Create GUI

The first part of the GUI displays the project's name and a list of radiobutons, each one wih a data set name to select the data set on which the statistics will be done. The user must select a data set.

  # Create project's title panel 
  titlePanel(tags$h2("STATISTICAL ANALYSIS AND LINEARITY FOR R DATA SETS", style = "color: blue;"))
  

Reactive Expression:

A reactive expression is an R expression that takes user gui input and returns a value. The reactive expression will update this value whenever the original input changes. THis is where he user selects a data set name from he radiobuttons list. If he user selecs a different data set, this expression will update the value.

 # Create radio buttons list of data set names to select data set          
  radioButtons("inDs", "Select dataset:", choices = names(datasets))
 # reactive expressions update when the input changes.
  ds <- reactive( datasets[[input$inDs]] )
  reactive(print(head(ds())))

varSelectInput("inVar", "Select variable:", datasets[[1]])

reactive(
 updateVarSelectInput(session, "inVar", data = ds())
)

Public: .now: function () .scheduleTask: function (millis, callback) @uploadEnd: function (jobId, inputId) @uploadInit: function (fileInfos) allowReconnect: function (value) cache: cache_mem, cachem clientData: reactivevalues clone: function (deep = FALSE) close: function () closed: FALSE createBookmarkObservers: function () cycleStartAction: function (callback) decrementBusyCount: function () defineOutput: function (name, func, label) dispatch: function (msg) doBookmark: function () downloads: Map, R6 exportTestValues: function (..., quoted_ = FALSE, env_ = parent.frame()) files: Map, R6 fileUrl: function (name, file, contentType = "application/octet-stream") flushOutput: function () freezeValue: function (x, name) getBookmarkExclude: function () getCurrentOutputInfo: function () getCurrentTheme: function () getOutput: function (name) getTestSnapshotUrl: function (input = TRUE, output = TRUE, export = TRUE, format = "json", groups: NULL handleRequest: function (req) incrementBusyCount: function () initialize: function (websocket) input: reactivevalues isClosed: function () isEnded: function () makeScope: function (namespace) manageHiddenOutputs: function (outputsToCheck = NULL) manageInputs: function (data, now = FALSE) ns: function (id) onBookmark: function (fun) onBookmarked: function (fun) onEnded: function (endedCallback) onFlush: function (flushCallback, once = TRUE) onFlushed: function (flushedCallback, once = TRUE) onInputReceived: function (callback) onRestore: function (fun) onRestored: function (fun) onSessionEnded: function (sessionEndedCallback) onUnhandledError: function (callback) options: list output: shinyoutput outputOptions: function (name, ...) progressStack: list reactlog: function (logEntry) registerDataObj: function (name, data, filterFunc) registerDownload: function (name, filename, contentType, func) reload: function () request: environment requestFlush: function () resetBrush: function (brushId) restoreContext: RestoreContext, R6 rootScope: function () sendBinaryMessage: function (type, message) sendChangeTabVisibility: function (inputId, target, type) sendCustomMessage: function (type, message) sendInputMessage: function (inputId, message) sendInsertTab: function (inputId, liTag, divTag, menuName, target, position, sendInsertUI: function (selector, multiple, where, content) sendModal: function (type, message) sendNotification: function (type, message) sendProgress: function (type, message) sendRemoveTab: function (inputId, target) sendRemoveUI: function (selector, multiple) setBookmarkExclude: function (names) setCurrentTheme: function (theme) setShowcase: function (value) showProgress: function (id, persistent = FALSE) singletons: startTiming: function (guid) token: 7be6db8219e2f55839dd621af64b5ab1 unhandledError: function (e, close = TRUE) updateQueryString: function (queryString, mode) user: NULL userData: environment wsClosed: function () Private: .clientData: ReactiveValues, R6 .input: ReactiveValues, R6 .outputOptions: list .outputs: list bookmarkCallbacks: environment bookmarkedCallbacks: environment bookmarkExclude: busyCount: 1 closedCallbacks: environment currentOutputName: outf94917098d573b21 currentThemeDependency: function (x) cycleStartActionQueue: list enableTestSnapshot: function () fileUploadContext: environment flushCallbacks: environment flushedCallbacks: environment getBookmarkExcludeFuns: list getOutputOption: function (outputName, propertyName, defaultValue) getSnapshotPreprocessInput: function (name) getSnapshotPreprocessOutput: function (name) inputMessageQueue: list inputReceivedCallbacks: environment invalidatedOutputErrors: Map, R6 invalidatedOutputValues: Map, R6 outputInfo: list outputValues: list progressKeys: registerBookmarkExclude: function (fun) registerSessionEndCallbacks: function () restoreCallbacks: environment restoredCallbacks: environment sendErrorResponse: function (requestMsg, error) sendMessage: function (...) sendResponse: function (requestMsg, value) shouldSuspend: function (name) showcase: FALSE startCycle: function () storeOutputValues: function (values = NULL) testExportExprs: list testMode: FALSE testSnapshotUrl: session/7be6db8219e2f55839dd621af64b5ab1/dataobj/shinyte ... timingRecorder: ShinyServerTimingRecorder, R6 unhandledErrorCallbacks: environment websocket: WebSocket, R6 withCurrentOutput: function (name, expr) write: function (json)

I solved the problem by assigning the reactive expression to a variable

reactive(
 data_input <- updateVarSelectInput(session, "inVar", data = ds())
)

You should use observe() instead of reactive()like:

observe(updateVarSelectInput(session, "inVar", data = ds()))

Thank you!. osberve() works with my application, but it does not work in the rmarkdown document. If I use observe i get: I guet the error: "Warning: Error in [[: attempt to select less than one element in get1index"

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.