###Description
I am trying to build a Shiny app for the education sector but I am wrestling with renderTable()
. The output I wish to see in ShinyApp I see in RStudio. The code fails to generate a 2 by 2 table in Shiny.
An example of the code view successfully in RStudio is: info %>% group_by(campus) %>% summarise(funded = n())
, where 'campus' is 1 of the variables. In RStudio a summary table (2 by 2) is generated with 2 named columns and 2 rows.
In Shiny the user must be able to choose any of the variables contained in names(info)
. I achieve this by using the function `selectInput()'.
For the code below, renderTable()
does not output a summary table. Instead it is a total count - a count of the total rows, not a summary of the totals of each unique element in a variable.
I think the error is in my renderTable()
function code.
Please take a look if you have a moment or direct me to a route that will take me toward a solution.
Thank you.
My sessionInfo appears after the code below.
library(shiny)
library(tidyverse)
info <- check_data <- structure(list(campus = c("athlone", "athlone", "athlone", "athlone","pinelands", "pinelands", "pinelands", "pinelands", "pinelands","pinelands"),
block = c("l0", "l0", "l0", "l0", "l0", "l0", "l0","ys", "ys", "ys"),
qualification = c("l2: automotive repair & maintenace nqf","l2: automotive repair
& maintenace nqf", "l2: automotive repair & maintenace nqf","l2: automotive repair
& maintenace nqf", "l2: electrical engineering nqf","l2: electrical engineering
nqf", "l2: electrical engineering nqf","ncv3: electrical infrastructure cnstr l3", "ncv3: electrical infrastructure cnstr l3","ncv3: electrical infrastructure cnstr l3"),
type = c("f", "f","f", "f", "f", "f", "f", "e", "e", "e"),
employer = c("null","null", "null", "null", "null", "null", "null", "null", "null","null")), row.names = c(NA, 10L), class = "data.frame")
info <- info %>% select(c(2, 3, 4, 8, 10))
ui <- fluidPage(
selectInput(inputId = "choice",
label = "Select group",
choices = names(info),
selected = c("qualification")),
tableOutput(outputId = "fund")
)
server <- function(input, output) {
headcount <- reactive({
req(input$choice)
info %>% group_by(input$choice) %>% summarise(funded = n())
})
# Headcount
output$fund <- renderTable({
headcount()
})
}
shinyApp(ui = ui, server = server)
My sessionInfo()
is below:
>R version 3.5.1 (2018-07-02)
>Platform: x86_64-apple-darwin15.6.0 (64-bit)
>Running under: macOS High Sierra 10.13.6
>Matrix products: default
>BLAS:
>/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecL>ib.framework/Versions/A/libBLAS.dylib
>LAPACK: >/Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dyli>b
>locale:
>[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
>attached base packages:
>[1] stats, graphics, grDevices utils, datasets, methods, base
>other attached packages:
>[1] bindrcpp_0.2.2, forcats_0.3.0, stringr_1.3.1, dplyr_0.7.6
>[5] purrr_0.2.5, readr_1.1.1, tidyr_0.8.1, tibble_1.4.2
>[9] ggplot2_3.0.0, tidyverse_1.2.1, shiny_1.1.0
>loaded via a namespace (and not attached):
>[1] tidyselect_0.2.4, haven_1.1.2, lattice_0.20-35, colorspace_1.3-2
>[5] htmltools_0.3.6, yaml_2.2.0, utf8_1.1.4, rlang_0.2.1
>[9] later_0.7.3, pillar_1.3.0, withr_2.1.2, glue_1.3.0
>[13] modelr_0.1.2, readxl_1.1.0, bindr_0.1.1, plyr_1.8.4
>[17] munsell_0.5.0, gtable_0.2.0, cellranger_1.1.0, rvest_0.3.2
>[21] httpuv_1.4.5, fansi_0.2.3, broom_0.5.0, Rcpp_0.12.18
>[25] xtable_1.8-2, promises_1.0.1, scales_0.5.0, backports_1.1.2
>[29] jsonlite_1.5, mime_0.5, hms_0.4.2, digest_0.6.15
>[33] stringi_1.2.4, grid_3.5.1, cli_1.0.0, tools_3.5.1
>[37] magrittr_1.5, lazyeval_0.2.1, crayon_1.3.4, pkgconfig_2.0.1
>[41] Matrix_1.2-14, xml2_1.2.0, lubridate_1.7.4, assertthat_0.2.0
>[45] httr_1.3.1, rstudioapi_0.7, R6_2.2.2, nlme_3.1-137
>[49] compiler_3.5.1