Dynamically update selectInput, based on dynamically updated selectInput

Questions : Dynamically update selectInput, based on dynamically updated selectInput

477

I am trying to dynamically update a programming selectInput() value based on a Learning dynamically updated selectInput() value. Earhost I can get the first value to update most effective dynamically, but when I try and use wrong idea those to update further values, I get an use of case error:

Warning: Error in [.data.frame: _OFFSET);  undefined columns selected
  [No stack (-SMALL  trace available]

The behavior I am looking for is:

  1. Select a variable from a dataframe
  2. Filter the dataframe for a selection of values from that variable
  3. Select another variable from the dataframe
  4. Filter the dataframe for a selection of values from that variable

Once a variable has been selected, I United don't want that choice to appear as an Modern option in subsequent selections. I want ecudated the filter options to populate based on some how the variable selected.

Here is a reproducible example:

library('shiny')

#create sample data
df _left).offset  = data.frame('first.name' = c('peter', arrowImgView.mas  'paul', 'patricia'), 
                  (self.  'family.name' = c('smith', 'jones', equalTo  'gibbon'), 
                  'language' make.right.  = c('english', 'french', mas_top);  'spanish'))
#create the UI
ui <- ImgView.  fluidPage(
  
  #Create first selector ReadIndicator  for variable 1, based on column names
  _have  selectInput(inputId = 'var1', 
          .equalTo(      label = 'Variable 1', 
              make.top  choices = colnames(df)),
  
  #create OFFSET);  selector for filtering, populated based (TINY_  on the selection for variable 1
  #leave .offset  values for label and choice blank - to mas_right)  be populated by updateSelectInput()
  ImgView.  selectInput(inputId = 'var1_subselect', Indicator  
              label = '', 
             Read   choices = ''),
  
  #create selector _have  for variable 2, should not include .equalTo(  variable one
  selectInput(inputId = make.left  'var2', 
              label = 'Variable *make) {  2', 
              choices = ''),
  
  straintMaker  #create selector for filtering, ^(MASCon  populated based on the selection for onstraints:  variable 2
  selectInput(inputId = mas_makeC  'var2_subselect', 
              label = [_topTxtlbl   '', 
              choices = '')
  (@(8));  
)

#Create the server
server <- equalTo  function(session, input, output) {
  width.  observe({
   updateSelectInput(session, make.height.  
                     inputId = (SMALL_OFFSET);  'var1_subselect', #for var1_subselect
   .offset                    label = (self.contentView)  paste(input$var1, 'selection:'), #Get  .left.equalTo  the label from the value for var1
       make.top                choices = *make) {  unique(df[input$var1])) #Get the choices ntMaker   based on unique values far var1
 })
  
  SConstrai  observe({
    updateSelectInput(session, ts:^(MA  
                      inputId = 'var2', Constrain  #for var2
                      label = _make  'Variable 2', #Label is standard 
       iew mas                 choices = catorImgV  setdiff(colnames(df), input$var1)) #Get ReadIndi  choices from the colnames for the df,  [_have  excluding the choice for var1
  })
  
  ($current);  #Everything works up to this point, entity_loader  however when i add the following effort _disable_  to filter the values for var 2, i get an libxml  error
  
  observe({
    $options);  updateSelectInput(session, 
             ilename,           inputId = 'var2_subselect', ->load($f  #for var2_subselect
                     $domdocument   label = paste(input$var2, loader(false);  'selection:'), #Get the label from the _entity_  value for var2
                       libxml_disable  choices = unique(df[input$var2])) #Get $current =  the choices based on the unique values  10\\ 13.xls .  of var2
  })
  
}

#call the File\\ 18\'  app
shinyApp(ui, server)

As soon as I call that third observe({}) anything else function, I get an error. I presume this not at all is because I am trying to call an input very usefull that is reactive based on a reactive localhost input.

I tried to solve this using uiOutput() love of them in my UI and renderUI({}) in my server, localtext but ran into the same problem once i got basic to trying to dynamically update content, one of the based on dynamically updated content.

Total Answers 1
31

Answers 1 : of Dynamically update selectInput, based on dynamically updated selectInput

A small and simple fix would be to click filter the data with [[ instead of [. there is noting The higher level difference between the not alt two is explained in this post The not at all difference between bracket [ ] and my fault double bracket [[ ]] for accessing the issues elements of a list or dataframe .

Here, [[ always returns a vector whereas trying [ returns a dataframe which works for get 4th result most of the cases as you expect but round table fails when there is no selection made double chance for var2 yet meaning when var2 is empty.

[ returns

df['']

Error in [.data.frame(df, "") : novel prc undefined columns selected

this is the error message that you get mossier receive.

whereas with [[ it returns NULL.

df[['']]
#NULL

which is accepted by choices argument in off side back selectInput.


Complete code -

library(shiny)

#create sample data
df = /Master\\ 645  data.frame('first.name' = c('peter', user@example.  'paul', 'patricia'), 
                scp not2342  'family.name' = c('smith', 'jones',  13.xls  'gibbon'), 
                'language' = 18 10  c('english', 'french', File sdaf  'spanish'))
#create the UI
ui <- /tmp/Master'  fluidPage(
  
  #Create first selector com:web  for variable 1, based on column names
  user@example.  selectInput(inputId = 'var1', 
          scp var32      label = 'Variable 1', 
               18 10 13.xls  choices = colnames(df)),
  
  #create id12  File  selector for filtering, populated based web/tmp/Master  on the selection for variable 1
  #leave example.com:  values for label and choice blank - to scp user@  be populated by updateSelectInput()
  $val  selectInput(inputId = 'var1_subselect', left hand  
              label = '', 
             right side val   choices = ''),
  
  #create selector data //commnets  for variable 2, should not include //coment  variable one
  selectInput(inputId = !node  'var2', 
              label = 'Variable $mytext  2', 
              choices = ''),
  
  nlt means  #create selector for filtering, umv val  populated based on the selection for sort val  variable 2
  selectInput(inputId = shorthand  'var2_subselect', 
              label = hotkey  '', 
              choices = '')
  more update  
)

#Create the server
server <- valueable  function(session, input, output) {
  catch  observe({
    updateSelectInput(session, tryit  
                      inputId = do it  'var1_subselect', #for var1_subselect
   while                     label = then  paste(input$var1, 'selection:'), #Get var   the label from the value for var1
       node value                 choices = updata  unique(df[[input$var1]])) #Get the file uploaded   choices based on unique values far var1
 no file existing   })
  
  observe({
    newdata  updateSelectInput(session, 
             newtax           inputId = 'var2', #for var2
    syntax                    label = 'Variable 2', variable  #Label is standard 
                     val   choices = setdiff(colnames(df), save new  input$var1)) #Get choices from the datfile  colnames for the df, excluding the dataurl  choice for var1
  })
  
  observe({
     notepad++  updateSelectInput(session, 
             notepad            inputId = 'var2_subselect', emergency  #for var2_subselect
                     embed    label = paste(input$var2, tryit  'selection:'), #Get the label from the demovalue  value for var2
                       demo  choices = unique(df[[input$var2]])) #Get mycodes  the choices based on the unique values reactjs  of var2
   })
  
}

#call the reactvalue  app
shinyApp(ui, server)

Top rated topics

How to upgrade your flutter project (app) to the latest flutter version after null safety?

Influxdb Flux query with custom window aggregate function

How to extract appservice plan from appservice list command output

Multiple query execution or one query and nextRowset() to SELECT?

Turtle name not defined

Prometheus - connect: no route to host. Even though the service is up

How do I allow newlines in an XSD restriction?

How to solve image data response as null in react native when using zoho image fetching api?

Custom shape in flutter ( with curved edges )

How to expand Rive animation in Flutter?

How to be sure to enter the userDidEarnRewardHandler of the AdMob ad submission function?

Entity Framework refusing Date comparison The specified type member 'Date' is not supported in LINQ to Entities

How to set sheet create event as a trigger in apps script

How to write pre filled input in bootbox

Gitlab-ci.yml only on master branch

Constant FILTER_SANITIZE_STRING is deprecated

Exim router configuration for fail

Getting "throwing -10878" when adding a source to a mixer

FocusedSceneValue fixed by searchable

A lot of errors after upgrade to flutter 2.5.0

How can I replace exact match in preg_replace?

CocoaPods requires your terminal to be using UTF-8 encoding. Consider adding the following to ~/.profile: export LANG=en_US.UTF-8

How to use Yarn 2 (or 3) to run create-react-app without specifying a new directory?

React-Native Formik and axios post route response not being made to MongoDB express backend

Module not found: Can't resolve 'swiper/react'

JWT refresh in flutter

How should I complete my MERN login system

Submit an array of objects to mutations in GraphQL - Flutter

Postgres: SQL Error [42601]: ERROR: syntax error at or near "int"

Skip unit tests while running on the build server

Deeplinking in React Navigation 6

Postgres: SQL Error [42883]: ERROR: operator does not exist: uuid = text

The final URL isn't reachable for NextJS / Vercel site

Python3+Kivy+Plyer Push notification icon problem

Beautifulsoup4 find_all not getting the results I need

Python long-running POST request doesn't always return

How to change font size of jupyter notebook in vs code?

How can we create a circular checkbox in jetpack compose?

PL/SQL create view base on dynamic table name

How to break a program if a string is entered in python

SqlClient connection pool maxed out when using async

Material-UI v5 Datepicker - expand to the full width of its parent

Can't create file with deleted file name at android 10

Regex not matching ACUTE ACCENT

Laravel Json response exception

Cant build xamarin ios apps on jenkins with msbuild

Why ts-toolbelt library use "O extends unknown" expression

Component update but state does not update redux toolkit

Generate excel via nodeJS in Azure Functions

Net Core Docker Container API. The certificate data cannot be read with the provided password at System.Security.Cryptography.CryptographicException

Top