0

Can we do aggregation on the fly based on user input and display the same using R for a large data? The data should be displayed in the UI with editable options. Once the user changes values for certain rows/columns the corresponding aggregate table should be rendered aside of this input data. It would be useful if I could see some code to implement the same. Thanks. A small example which I found for better understanding. Here row gets added on each user input. Can we implement the same with only single row giving two columns as user input and based on that the last column(sum) should keep changing.

library(shiny)
runApp(list(
ui=pageWithSidebar(headerPanel("Adding entries to table"),
                 sidebarPanel(textInput("text1", "Column 1"),
                              textInput("text2", "Column 2"),
                              actionButton("update", "Update Table")),
                 mainPanel(tableOutput("table1"))),
server=function(input, output, session) {
values <- reactiveValues()
values$df <- data.frame(Column1 = numeric(0), Column2 = numeric(0))
#isolate(values$df[,] <- c(input$text1, input$text2))
newEntry <- observe({
   if(input$update > 0) {
     newLine <- isolate(c(input$text1, input$text2))
     isolate(values$df[nrow(values$df),] <- c(input$text1, input$text2))
   }
 })
 output$table1 <- renderTable({cbind(values$df, Rowsum = apply(values$df, 1, 
 function(x) sum(as.numeric(x))))})
 }))

sample output of above program

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58

0 Answers0