This works.
I have added some packages that you missed, and also presented some options that work with this dataset. Not sure how they will play with your real data though:
# the options:
#1 filter(str_detect(Species, fixed(input$Species, ignore_case=TRUE))) # starts with nothing
#2 filter(str_detect(Species, str_to_lower(input$Species))) # starts with all data - converts to lower, which matches the data
library(shiny)
library(tidyverse) # changed
library(shinyWidgets)
library(DT) # added
df <- iris
df$Species <- as.character(df$Species)
#shiny server ui
ui <- fluidPage(
downloadButton("download", "Download .csv"),
align="center",
titlePanel("Data"),
fluidRow(
column(3,
searchInput(inputId = "Species",
label = "Species filter",
btnSearch = icon("search"),
btnReset = icon("remove"),
width = "75%"
)
),
column(6,
DT::dataTableOutput("df")
),
column(3)
)
)
#shiny server back end
server <- function(input, output, session) {
datasetInput1 <- reactive({
reactivedata <- df
if (is.character(input$Species)) {
reactivedata <- reactivedata %>%
# filter(str_detect(Species, fixed(input$Species, ignore_case=TRUE))) # starts with nothing
filter(str_detect(Species, str_to_lower(input$Species))) # starts with all data - converts to lower, which matches the data
}
reactivedata <- reactivedata
return(reactivedata)
})
output$df <- renderDT({
datatable(datasetInput1(), rownames = TRUE, options = list(dom = 'p', ordering = T))
})
output$download <- downloadHandler(
filename = "report.csv",
content = function(file) {
write.csv(datasetInput1(), file)
}
)
}
#run shiny server
shinyApp(ui = ui, server = server)