Ordering reactive data

Hello, I am trying to create a game leaderboard for my rshiny app. Currently I have a reactive form where the user fills in data, and once submitted it is then reflected in a data table. I am trying to order the data table such that it arranges the data in order of the highscore of the players, and I am having trouble doing so. Assistance would be much appreciated, thanks!

This is the code with regards to what I've mentioned:

fields <- c("Name","Final Waste Score","Date")
  saveData <- function(data) {
    data <- as.data.frame(t(data))
    if (exists("responses")) {
      responses <<- rbind(responses, data)
    } else {
      responses <<- data
    }
  }
  
  loadData <- function() {
    if (exists("responses")) {
      responses
    }
  }
  
  
  # Whenever a field is filled, aggregate all form data
  #formData is a reactive function
  formData <- reactive({
    data <- sapply(fields, function(x) input[[x]])
    data
  })
  
  # When the Save button is clicked, save the form data
  observeEvent(input$save, {
    saveData(formData())
  })
  tb1 <- reactive({
    input$save
    loadData()
  })
  mytb <- reactive({
    tb1 <- tb1()
    tb1$"Name" <- as.character(tb1$"Name")
    tb1$"Final Waste Score" <- as.character(tb1$"Final Waste Score")
    tb1$"Date" <- as.Date(tb1$"Date")
    colnames(tb1) <- c("Name", "Final Waste Score", "Date")
    tb1
  })
  output$responses <- DT::renderDataTable(
    mytb()
    )

Tidyverse / dplyr has arrange function for ordering tables. Also you won't want to convert scores to characters as alphabetic sorting won't be the same as numeric sorting.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

Noted, thanks for the advice.
For the arrange function, which part of my code should it be in? Thanks in advance

i suppose you'd arrange tb1 so mytb would have your desired order