I\'m trying to build a Shiny app that subsets a data frame (to only include rows where a categorical variable matches the user-select input from the UI) before the data is proce
I had the same issue and spent a couple of hours trying to figure it out. Once you have assigned the reactive object, you need to use target_inventory() in order to refer to it (as BenBarnes mentioned in the comment section).
Here is a MWE (minimum working example)
ui.R
#ui
library(shiny)
shinyUI(fluidPage(
#User dropbox
selectInput("state", "Choose state", choices=c("MA", "CA", "NY"))
#Print table to UI
,tableOutput("table1")
))
server.r
#server
library(shiny)
shinyServer(function(input,output){
category <- c("MA", "CA", "NY")
population <- c(3,8,4)
df <- data.frame(category,population)
df_subset <- reactive({
a <- subset(df, category == input$state)
return(a)
})
output$table1 <- renderTable(df_subset()) #Note how df_subset() was used and not df_subset
})