error when attempting compareGroups with reactive text in shiny

16 views
Skip to first unread message

alden...@gmail.com

unread,
Jun 1, 2018, 2:29:01 AM6/1/18
to compareGroups Forum
Hello,
I cannot seem to get the compareGroup and createTable to work with reactive elements in shiny. I have put the ui and server code below. The error message notes that createTable does not recognize 'res' as a valid compareGroup function. All the facilities are separate datasets from the one called 'allclinics,' but I broke them apart as earlier I had attempted the subset within compareGroup and had similar problems with the reactive issue. Any help is much appreciated.


ui <- fluidPage(
titlePanel("Tests of Association"),

# Sidebar

sidebarLayout(
sidebarPanel(
HTML('</br>'),
selectInput("facilitypick", h5("Choose a Facility:"), choices = c("All Facilities","Facility A","Facility B","Facility C")),
# main panel

mainPanel(
verbatimTextOutput("AssocTable")

)

))

server <- function(input, output) {

datasetInput <- reactive({
switch(input$facilitypick,
"All Facilities" = allclinics,
"Facility A" = FacA,
"Facility B" = FacB,
"Facility C" = FacC)
})


#make compareGroups formula
res<-reactive({compareGroups(year~.,data=datasetInput())})
restab<-createTable(res,show.n=TRUE)

#res<-compareGroups(year~.,data= datasetInput())
#restab<-createTable(res, show.n = TRUE)


#print table
output$AssocTable <- renderPrint({
restab
})

}

# Run the application
shinyApp(ui = ui, server = server)

compareGroups

unread,
Jun 21, 2019, 12:36:55 PM6/21/19
to compareGroups Forum
Below there is the code with some minor modifications. Basically, there were some instructions where you needed the shiny reactive function.
However, I couldn't reproduce this example since I have not the "allclinics", "FacA", "FacB" nor "FacC" data sets.



ui <- fluidPage(
  titlePanel("Tests of Association"),

  # Sidebar 
  sidebarLayout(
    sidebarPanel(      
      HTML('</br>'),
      selectInput("facilitypick", h5("Choose a Facility:"), choices = c("All Facilities","Facility A","Facility B","Facility C"))       
    ),
    mainPanel(
      verbatimTextOutput("AssocTable")
    )                        
  )
)
  
server <- function(input, output) {
    
    datasetInput <- reactive({
      switch(input$facilitypick,
             "All Facilities" = allclinics,
             "Facility A" = FacA,
             "Facility B" = FacB,
             "Facility C" = FacC)
    })
    
    
    #make compareGroups formula
    res<-reactive({compareGroups(year~.,data=datasetInput())})
    
    #restab<-createTable(res,show.n=TRUE)
    restab <- reactive(createTable(res(),show.n=TRUE)) # ISAAC> reactive required and also res with brackets
    
    
    #res<-compareGroups(year~.,data= datasetInput())
    #restab<-createTable(res,  show.n = TRUE)
    
    
    #print table
    output$AssocTable <- renderPrint({
      # restab
      restab() #ISAAC> restab is a reactive object and must be called with brackets
Reply all
Reply to author
Forward
0 new messages