mardi 23 juillet 2019

checkboxGroupInput displaying list of table elements rather than table itself

I am creating an R Shiny application primarily using checkboxGroupInput where for each checkbox name I check, the corresponding table should display in the main UI panel. I have linked each checkbox option to its corresponding table (already in my previous script) in the "choices" argument of checkboxGroupInput. I use eventReactive to make a working button and renderTable to produce the appropriate tables. However, what displays in the main panel when I click the button is a list of each cell in the table rather than the table itself. This list of values looks a bit like this:

list(CUI = "C05372341", LAT = "ENG", TS = "P", LUI = "L0883457", STT = "PF", SUI = "S13423408", ISPREF = "N", AUI = "A10344304", SAUI = "21823712", SCUI = "1341953", SDUI = NA, SAB = "LKDHDS", TTY = "IN", CODE = "139433", STR = "Pramlintide", SRL = "0", SUPPRESS = "Y", CVF = "4354")

I would like this to have been printed in table form.

When I simply use renderTable({table_name}) on any given one of the tables, the table prints in the main panel how I would like it to. However, when I use eventReactive, name that variable, and renderTable on that variable, that is when the list of table values prints instead. Any ideas?

library(shiny)

ui <- fluidPage(
  titlePanel("RxNorm Diabetic Drug Mapping based on Epocrates Classes"),
  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput("drugs", "Drug Class", choices = list("ALPHA GLUCOSIDASE INHIBITORS" = agi, "AMYLIN MIMETICS" = pramlintide, "BIGUANIDES" = biguanides, "DOPAMINE AGONISTS" = bromocriptine, "DPP4 INHIBITORS" = dpp4, "GLP1 AGONISTS" = glp1, "INSULINS" = insulins, "MEGLITINIDES" = meglitinides, "SGLT2 INHIBITORS" = sglt2, "SULFONYLUREAS" = sulfonylureas, "THIAZOLIDINEDIONES" = thiazolidinediones)), 

      actionButton("button", "Retrieve Data")
    ),

    mainPanel(
      tableOutput("results")
    )
  )
)

server <- function(input, output) {
   table_reactive <- eventReactive(input$button, {
     input$drugs
   })

   output$results <- renderTable({
     table_reactive()
   })
}

shinyApp(ui = ui, server = server)




Aucun commentaire:

Enregistrer un commentaire