Shiny Query Beginner

library(shiny)
library(tidyverse)
library(data.table)
library(DT)

ui <- fluidPage(

selectInput(inputId="C1",label='filt1',choices=colnames(mtcars)),
selectInput(inputId="C2",label='filt2',choices=colnames(mtcars)),

DT::dataTableOutput("table1")
)

server<- function(input,output,session) {

data<-mtcars
setDT(data)

output$table1<-DT::renderDataTable({

data[,.(get(input$C1),get(input$C2)),]

#mtcars %>%
#select(input$C1,input$C2)

})

}

shinyApp(ui=ui,server=server)

For the data table ,why we need to add the get command where as for dplyr the same input$Col names works

input$C1 will be a simple string character type. The curious use of get is therefore a data.table quirk and not a shiny thing per se.
http://brooksandrew.github.io/simpleblog/articles/advanced-data-table/#method-2-quotes-and-get

1 Like