I have a little app that lists customers, items and sales. I want to generate a lookup list from the table but get two columns if I try to order the list using keyby. It is probably VERY simple but I'm confused. Code below....
library(data.table)
company=c("A","S","W","L","T","T","W","A","T","W")
item=c("Thingy","Thingy","Widget","Thingy","Grommit","Thingy","Grommit","Thingy","Widget","Thingy")
sales=c(120,140,160,180,200,120,140,160,180,200)
salesdt<-data.table(company,item,sales)
server <- function(input, output) {
output$theCustomersList <- renderUI({
list(
selectInput("customer", "Choose a customer:",
choices = salesdt[,unique(company), keyby=company]
,selectize=FALSE
,selected="A"
)
)
})
output$result <- renderTable(
salesdt[company%in%c(input$customer),
.(valuesold=sum(sales)), item
]
)
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
uiOutput("theCustomersList")
),
mainPanel(tableOutput('result'))
)
)
shinyApp(ui = ui, server = server)
To clarify.... my question is how do I change
salesdt[,unique(company), keyby=company]
to get get one column but ordered.