简体   繁体   中英

Error in match(el, set, 0L) : 'match' requires vector arguments?

In running the following code in Shiny in R :

client_report_type = reactive({ input$report_type })
  if ( is.element(client_report_type,"Enterprise_user")) 

...

I encountered the following error message:

Error in match(el, set, 0L) : 'match' requires vector arguments 

Does anyone know what does it mean, and how to resolve the problem? Thanks!

You don't need to put an input inside a reactive to get the value, but the input should be inside of a reactive expression. Anything outside a reactive expression will be execute only once when the shiny app starts. And if you try to use an input value outside a reactive expression there will be an error. Depending of what you are going to do with input$report_type you can put it in a reactive (of course), observe , or observeEvent .

Here are some basic examples:

reactive:

dat <- reactive({ 
  if ( is.element(input$report_type,"Enterprise_user")) {
    ...
    myData
  } else {
    NULL
  }  
})

observe:

observe({
  if (is.null(input$report_type))
    return()

  if ( is.element(input$report_type,"Enterprise_user"))
   ...
})

observeEvent:

observeEvent(input$report_type, {
  if ( is.element(input$report_type,"Enterprise_user"))
   ...
}) 

Here is great tutorial about shiny and reactivity: http://deanattali.com/blog/building-shiny-apps-tutorial/#reactivity-101

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM