I'm trying to create a Shiny/flexdashboard Markdown file, and I've stuck the following in a R code chunk. Basically, it subsets the input dataframe using two inputs - the second input depends on the first:
output$Box1 = renderUI(selectInput('sector',
'Sector',
c(levels(test$Sector),"pick one"),
"pick one") )
output$Box2 = renderUI(
if (is.null(input$sector) || input$sector == "pick one"){return()
}else selectInput('FA',
'Functional Area',
c(levels(test$FA[which(test$Sector == input$sector)]),"pick one"),
"pick one"))
subdata1 = reactive(test[which(test$Sector == input$sector),])
subdata2 = reactive(subdata1()[which(subdata1()$FA == input$FA),])
renderDataTable({subdata2()}, options = list(dom = 'lpt'))
Now, this works fine to subset the data frame (Sector, then FA), and the subsetted data frame is visible in the dashboard via renderDataTable
.
What I'd like to do is to perform things like table
on the reactive data subset, to create a contingency table on factor levels:
data1 <- reactive(table(subdata2()$UserCountry))
and then further use this new table, for example:
renderDataTable({data1()}, options = list(dom = 'lpt'))
When I try this, the new table doesn't render.
Is there a way of running this successfully?