Q:

How to look for multiple data sets for use in Shiny Interactive Document in RStudio?

I have started learning about Shiny Interactive documents and am not a programmer so please pardon my ignorance.
This is based on rmarkdown version 2 website 'Advanced' topics page. I have the RStudio version 0.98.1028.
I am trying to display the head of vectors a or b in the shiny doc. Here's what I did:
```{r two, echo = FALSE}

a <- 1:10
b <- 13:20
a
b
selectInput("dataset2", "Choose Dataset:", c('a', 'b'))

activeDataset2 <- reactive({
  get(input$dataset2)
})

renderTable({
  head(activeDataset2(), 5)
})

```

Upon clicking Run Document, I get the Error no applicable method for 'xtable' applied to an object of class "c('integer', 'numeric')".
In the example on the website, an argument pos is used to look for the data sets. I don't know how to use that in this context. Please help.

A:

renderTable uses xtableto produce its tables:
a <- 1:10
> library(xtable)
> xtable(a)
Error in UseMethod("xtable") : 
  no applicable method for 'xtable' applied to an object of class "c('integer', 'numeric')"

so the problem here is that xtable requires an object passed to it with an xtable method defined:
> methods(xtable)
 [1] xtable.anova*           xtable.aov*             xtable.aovlist*        
 [4] xtable.coxph*           xtable.data.frame*      xtable.glm*            
 [7] xtable.lm*              xtable.matrix*          xtable.prcomp*         
[10] xtable.summary.aov*     xtable.summary.aovlist* xtable.summary.glm*    
[13] xtable.summary.lm*      xtable.summary.prcomp*  xtable.table*          
[16] xtable.ts*              xtable.zoo*            

You could change your output to a data.frame
activeDataset2 <- reactive({
  out <- get(input$dataset2)
  `names<-`(data.frame(out), input$dataset2)
})

or you can write an appropriate xtable method for objects of class "c('integer', 'numeric')"

