Skip to contents

This function adds a new expense entry to the given data frame of expenses. It checks for the validity of the category and amount before adding.

Usage

add_expense(category, amount, expenses_data, selected_categories, session)

Arguments

category

A string specifying the category of the expense.

amount

A numeric value representing the amount of the expense. Must be non-negative.

expenses_data

A reactive value containing a data frame of expenses.

selected_categories

A reactive value storing the list of already selected categories.

session

The Shiny session object passed to showModal for displaying modals.

Value

Logical TRUE if the expense is successfully added, FALSE otherwise.

Author

Group C composed of Marc Bourleau, Eleonore Gillain, Khrystyna Khmilovska and Konstantinos Kourlimpinis.

Examples

if (FALSE) {
  # Simulate the environment of a Shiny app
  library(shiny)
  expenses_data <- reactiveVal(data.frame(category = character(), amount = numeric()))
  selected_categories <- reactiveVal(character())
  session <- shiny::getDefaultReactiveDomain()

  # Examples of add_expense function
  add_expense("Food", 50, expenses_data, selected_categories, session)
  add_expense("Transport", -10, expenses_data, selected_categories, session) # Invalid amount
  add_expense("Food", 30, expenses_data, selected_categories, session) # Category already exists
}