Reproduce table in Shiny

Hi! I'm trying to reproduce a simple summary table within Shiny. When I reproduce the table out of Shiny, it works perfectly fine. I subset the data by using subset(valueA OR valueB). Within Shiny, this needs to come from multiple selection input, so I use subset(input) but the summary table is not accurate anymore. Somehow the format of the input is not the same as valueA or valueB. How can I achieve that?

Here is the table that works fine. It creates 8 rows, 2 posting and 4 sources each:

df %>% subset(Posting.Title=="valueA" | Posting.Title=="valueB")%>%
group_by(Posting.Title,sources) %>% summarise(n=n()) %>%
mutate(num_of_opps = n) %>%
mutate(Percent_of_oppourtunities = round(num_of_opps/sum(num_of_opps),digits=2))

Here is the one that doesn't reproduce the same table. When there is 1 input, it is accurate, after multiple inputs, the number of rows per grouped variable doesn't match, for example if there are 4 sources for 1 posting, after multiple inputs, it only shows 3 sources for that posting and the numbers are miscalculated.

ui <- fluidPage(
selectInput(
inputId="job_post",
label="Select one or more job post to compare",
choices=df$Posting.Title,
selected = NULL,
multiple = TRUE,
selectize = TRUE,
width = NULL,
size = NULL
),
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),

plotlyOutput("graph3")

tableOutput('table')
)

server <- function(input, output) {

dt_f<- reactive({ df %>% subset(Posting.Title==input$job_post)%>%
group_by(Posting.Title,sources) %>% summarise(n=n()) %>%
mutate(num_of_opps = n) %>%
mutate(Percent_of_oppourtunities = round(num_of_opps/sum(num_of_opps),digits=2))
})
output$table <- renderTable(dt_f())
}

shinyApp(ui = ui, server = server)

Thank you!

if input$job_post can be multiple values then it stops making sense to == compare it against Posting.Title

#is this a single TRUE/FALSE ?
"a" == letters
"a" %in% letters
1 Like

This solution worked, thanks!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.