I have a shinydashboard app where I want to be able to reactively subset data by multiple variables and then create a barplot of the resulting subset.
I've successfully created the reactive subsetting but the barplot shows, every time, that the y values are the same for every x values, even though the printed subset shows they have different values.
Relevant UI:
tabItem(tabName = "subset",
fluidRow(
box( uiOutput("codePanel")),
box(selectInput("groupDset", label="Select Category",
choices = list("Evaluation"="evaluation",
"Incidence"="incidence",
"Involvement"="involve_idx",
"Funny" = "atts_raw_fun",
"Edgy" = "atts_raw_edgy",
"Disturbing" = "atts_raw_disturbing",
"Dramatic"= "atts_raw_dramatic",
"Mindless"= "atts_raw_mindless",
"Calming"= "atts_raw_calming",
"Intelligent"= "atts_raw_intelligent",
"Informative"= "atts_raw_informative",
"Scary"= "atts_raw_scary",
"Funny"= "atts_raw_funny",
"Relatable"= "atts_raw_relatable",
"Mean"= "atts_raw_mean",
"Size"="n_size"), selected = "evaluation")),
box(plotOutput(outputId = "bar1"))),
fluidRow(
box(width=NULL, DT::dataTableOutput("text"),style = "height:500px; overflow-y: scroll;overflow-x: scroll;"))
),
This is the server side
filt <- selectInput("codeInput",label ="choose code",
choices = as.list(unique(data$show_name)))
output$codePanel <- renderUI({ filt
})
dataset<-reactive({
subset(data, show_name == input$codeInput)
})
dataset2<-reactive({
subset(dataset(), select = c(input$groupDset,"grp_lev"))
})
output$text<-renderDataTable(dataset())
output$text2<-renderDataTable(dataset2())
#This plot seems to say that input$groupDset is a constant
output$bar1<-renderPlot({
ggplot(data=dataset2(), aes(x=grp_lev, y=input$groupDset, fill=grp_lev)) + geom_bar(stat = "identity")
})
When the plot is run from outside the shiny app with the same variables, but static, it works as expected and the y axis has tick marks. When called from the app, the y axis isn't articulated which makes me thing that input$groupDset
must be the wrong data type. Running it y=as.numeric(input$groupDset)
threw an error. Maybe because dataset2 is a closure function, the subsetting has to be formatted differently to slice it by reactive column value?
ggplot(data=subset(data, show_name =='Show 1'), aes(x=grp_lev, y= incidence, fill=grp_lev)) + geom_bar(stat = "identity")