I have a Shiny app based on a dataframe that looks like this:
ID Date result
1 1/1/2010 100
1 12/12/2010 200
2 1/1/2011 300
2 1/1/2011 400
Notice the double ID's...and for ID 2, two dates are the same.
When running, the app looks like this:
But the app gets confused when it is forced to consider ID #2, which has multiple of the same Dates:
The dropdown menu has a blank first choice, but the second choice is populated correct.
How could I correct this, so that the dropdown is populated with any number of identical dates?
(The more I think about this, it is feeling like a bug as opposed to simply wrangling functionality out of the object. It isn't hard to think of numerous situations where duplicate values would be of interest.)
Thanks for your attention.
app.R
library('shiny')
DF <- data.frame(ID=c(1,1,2,2), Date=c('1/1/2010', '12/12/2010', '1/1/2011', '1/1/2011'), result=c(100, 200, 300, 400))
DF$Date <- as.character(DF$Date)
server <- function(input, output, session) {
get_id <- reactive({
id <- DF[which(DF$ID == input$ID), ]
return(id)})
output$result <- renderText({
ans <- get_id()
print(ans)
paste("Result: ", ans$result)})
output$dates<-renderUI({
print(get_id()$Date)
selectInput('dates', 'Select date:', choices=get_id()$Date, selected=get_id()$Date[1])})
}
ui <- fluidPage(
fluidRow(column(2,
numericInput(inputId="ID", label="Pick an ID: ", value=1))),
column(2,
uiOutput("dates")),
column(3, mainPanel(textOutput("result")))
)
shinyApp(ui = ui, server = server)