I Am creating a dynamic update in R shiny with the following code using the iris dataset
write.csv(iris, file = "iris.csv", row.names = F)
# to create a local version of iris dataset
# next create UI
ui <- fluidPage(
fileInput("file", "Browse",
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
selectInput(inputId = "Speciesname", label = "Name",choices =
NULL,selected = NULL),
tableOutput("data")
)
#Create server
server <- function(input, output,session) {
df = reactive({
req(input$file)
return(read.csv(input$file$datapath))
})
observe({
choices1 = unique(df()$Species)
updateSelectInput(session,"Speciesname", choices = choices1)
})
output$data <- renderTable({
req(input$Speciesname)
df[as.character(input$Speciesname), ]
}, )
}
#Run app
shinyApp(ui, server)
I am able to read the file in. The subsetting however is showing the following error and the shiny app
Warning: Error in [: object of type 'closure' is not subsettable
[No stack trace available]
I am unable to understand or sort this error out. The code runs when I dont use a local copy of the dataset but use the built in R iris dataset. I request someone to guide me here
df(), as indf()[as.character(input$Speciesname), ]