I want to have a output table in the UI that has a conditional column sum based on the text of "Column 3".
Here is my example code:
library(shiny)
runApp(list(
ui=pageWithSidebar(headerPanel("Adding entries to table"),
sidebarPanel(textInput("text1", "Column 1", "66"),
textInput("text2", "Column 2", "100"),
textInput("text3", "Column 3", "Tony"),
actionButton("update", "Update Table")),
mainPanel(tableOutput("table1"))),
server=function(input, output, session) {
values <- reactiveValues()
values$df <- data.frame(Column3 = character(),
Column1 = numeric(0),
Column2 = numeric(0),
stringsAsFactors = FALSE)
newEntry <- observe({
if(input$update > 0) {
newLine <- isolate(c(input$text3, input$text1, input$text2))
isolate(values$df[nrow(values$df) + 1,] <- c(input$text3,
input$text1, input$text2))
}
})
output$table1 <- renderTable({values$df})
}))
If you click on the "Update Table" button twice, the output table that I would like to see it is:
Tony 132 200
The names in "Column 3" will be different depends on the input value from the sidebar. The output table should observe that, and then return all the names with sum of "Column 1" and sum of "Column 2" under that name.
I tried to create a new data frame using the aggregate function on the values$df
, but it is not working.