This Shiny application provides a user-friendly interface for time series forecasting using multiple machine learning models and integrates a Groq-powered chatbot via the ellmer R package for analyzing predictions and model metrics. The app allows users to select forecasting models, visualize results, and interact with a chatbot to gain insights into forecasts and accuracy metrics.
- Time Series Forecasting: Supports multiple models including Auto ARIMA, ARIMA with XGBoost, ETS, Prophet, Linear Regression, and
all_models. - Interactive UI: Select models, filter data by date range, and visualize forecasts with confidence intervals in a customizable plot (default height: 600px).
- Metrics Analysis: Displays model accuracy metrics (e.g., RMSE, MAE, MAPE) in a table.
- Chatbot Integration: Powered by Groq API , the chatbot analyzes forecast predictions and metrics, providing professional summaries and insights.
- Modular Code: Organized with utility functions in
utils.Rfor model fitting, forecasting, and metrics processing. - Error Handling: Robust validation and error notifications ensure a smooth user experience.
To run the app, ensure you have the following:
- R (version 4.0 or higher recommended)
- R Packages:
install.packages(c( "shiny", "shinythemes", "shinycssloaders", "xgboost", "tidymodels", "modeltime", "tidyverse", "lubridate", "timetk", "shinychat", "config", "ellmer" ))
- Groq API Key (free): https://console.groq.com/keys
- Data File: The app expects a CSV file (
data/autoforecasting.csv) with columnsdate(inYYYY-MM-DDformat) andvalue(numeric).
-
Clone the Repository:
git clone https://github.com/<your-username>/<your-repo-name>.git cd <your-repo-name>
-
Set Up the Data:
- Place your
autoforecasting.csvfile in thedata/directory. - Ensure the file has columns named
dateandvalue(note: the app renamesvalue.tovalueif necessary).
- Place your
-
Configure Groq:
- The repository includes a sample configuration file
example_config.yml. Copy and rename it toconfig.yml:cp example_config.yml config.yml
- Open
config.ymland insert your Groq API key (free tier works perfectly):default: groq_key: "gsk_your_real_key_here"
- How to get your Groq key (30 seconds, no credit card):
- Go to https://console.groq.com/keys
- Click “Create API Key”
- Copy the key (starts with
gsk_) - Paste it into
config.yml
- The repository includes a sample configuration file
-
Install Dependencies:
- Open R or RStudio and install the required packages listed above.
- Update packages if needed:
update.packages()
-
Run the App:
-
Open
app.Rin RStudio and click "Run App", or run from the R console:shiny::runApp()
-
The app will launch in your default web browser.
-
-
Forecasting:
- Select a model from the dropdown (e.g., "auto_arima", "prophet") or check "Plot All Models".
- Choose a date range using the date picker.
- Click "Plot" to generate the forecast plot and metrics table.
- View the forecast plot in the "Forecast Plot" tab (600px height) and metrics in the "Metrics Table" tab.
-
Chatbot Interaction:
- In the "Chatbot" section, type a question (e.g., "analyze predictions" or "summarize metrics").
- Click "Send" to receive a response from the Groq API chatbot.
- The chatbot provides insights into forecast predictions or model accuracy metrics based on your query.
-
Exit:
- Click the "Exit" button to stop the app.
├── app.R # Main Shiny app script
├── utils.R # Utility functions for model fitting, forecasting, and metrics
├── media # FIle media
├── data/ # Directory for input data
│ └── autoforecasting.csv # Sample data file (not included)
├── example_config.yml # Configuration file for Groq API (create manually)
└── README.md # This file
The config.yml file is critical for the chatbot functionality. Ensure the following variables are correctly set:
groq_key: Your Groq API key for authentication.
Security Note: Do not commit config.yml to your GitHub repository, as it contains sensitive API keys. Add it to .gitignore:
echo "config.yml" >> .gitignore- Metrics Table Not Displaying: Ensure
autoforecasting.csvhas valid data and sufficient observations (at least 12 rows). Check console output for errors. - Chatbot Errors: Verify
config.ymlsettings and nd Groq API key status. Ensure your API key is valid and the endpoint is accessible. - Model Errors: Some models (e.g., Prophet,
all_models) may fail with insufficient or malformed data. Check the console for debugging output (enabled viaoptions(shiny.error = browser)). - Package Issues: Update R packages to the latest versions. If issues persist, reinstall dependencies.
For additional help, check the console output in RStudio or open an issue in this repository.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/new-feature). - Commit your changes (
git commit -m "Add new feature"). - Push to the branch (
git push origin feature/new-feature). - Open a pull request.
Please include tests and documentation for new features.
- Built with Shiny for the web interface.
- Forecasting powered by modeltime and tidymodels.
- Chatbot integration via ellmer and Grok API.
This project is licensed under the BSD 2-Clause License. See the LICENSE file for details.
