I am making an app using the diamond dataset that I'd like to show the full table unless inputs are selected. However, if I select, say, cut by itself nothing appears. Also, if I select a lot of things no additional diamonds appear. Here's my code:
library(shiny)
library(DT)
library(tidyverse)
diamonds <- diamonds
#Shiny App
ui = fluidPage(
fluidRow(
column(2, selectizeInput(inputId = 'carat',
label = 'Select carat',
choices = unique(diamonds$carat),
selected = NULL,
multiple=TRUE)),
column(2, selectizeInput(inputId = 'cut',
label = 'Select cut',
choices = unique(diamonds$cut),
selected = NULL,
multiple=TRUE)),
column(2, selectizeInput(inputId = 'color',
label = 'Select color',
choices = unique(diamonds$color),
selected = NULL,
multiple=TRUE))
),
fluidRow (
column(12, dataTableOutput('data', height = '100px') )
)
)
server <- function(input, output, session) {
df_current <- reactive({
df <- diamonds%>%
filter(carat %in% ifelse(is.null(input$carat), carat, input$carat),
cut %in% ifelse(is.null(input$cut), color, input$cut),
color %in% ifelse(is.null(input$color), color, input$color))
df
})
output$data <- renderDataTable({
df_current()
})
}
shinyApp(ui = ui, server = server)
I am not sure why the reactive function df_current doesn't work correctly.
Thanks!
