Skip to contents

This guide explains the configuration of required and optional environment variables for the RPACT Cloud application. Environment variables can be defined in an .Renviron file to ensure they are correctly loaded when the application starts. They are particularly useful for deployment in Posit Connect.

General Environment Variables

ENV

  • Description: The current environment of the application.
  • Usage: Allows distinguishing between different environments, such as development and production.
  • Validation: Optional. If set, it is included in the email subject.
  • Example: ENV=production

SESSION_TIMEOUT_SECONDS

  • Description: The session timeout duration in seconds.
  • Usage: Specifies how long a session can be idle before it is terminated.
  • Validation: Must be a non-empty string containing only digits. The value is converted to an integer.
  • Example: SESSION_TIMEOUT_SECONDS=3600

MODULE_LOG_MESSAGES_ENABLED

  • Description: Indicates whether the log messages module is enabled.
  • Usage: Enables or disables the log messages module.
  • Validation: Must be a non-empty string with a value of either TRUE or FALSE.
  • Example: MODULE_LOG_MESSAGES_ENABLED=TRUE

LOG_LEVEL

  • Description: The logging level of the application.
  • Usage: Specifies the level of detail for log messages.
  • Validation: Must be one of the following values: trace, debug, info, warn, error, disabled.
  • Example: LOG_LEVEL=info

MAIL_VALIDATION_REGEX

  • Description: A regular expression for validating email addresses.
  • Usage: Used to validate the recipient email address.
  • Validation: Must be a valid regular expression. If not set, a default regular expression is used.
  • Example: MAIL_VALIDATION_REGEX=@example\.com$

MAIL_FROM

  • Description: The sender’s email address.
  • Usage: Specifies the email address from which emails are sent.
  • Validation: Must be a valid email address.
  • Example: MAIL_FROM=noreply@example.com

MAIL_REPLY_TO

  • Description: The reply-to email address.
  • Usage: Specifies the email address to which replies should be sent.
  • Validation: Must be a valid email address.
  • Example: MAIL_REPLY_TO=support@example.com

SMTP-Specific Environment Variables

The following variables configure the SMTP server and are optional. If no SMTP data is defined, all emails will be sent via the Mailgun account of RPACT using the Mailgun RESTful API.

MAIL_SMTP_USER

  • Description: The user name for the SMTP server.
  • Usage: Used to authenticate with the SMTP server.
  • Validation: Must be a non-empty string.
  • Example: MAIL_SMTP_USER=my_smtp_user

MAIL_SMTP_PASSWORD

  • Description: The password for the SMTP server.
  • Usage: Used to authenticate with the SMTP server.
  • Validation: Must be a non-empty string.
  • Example: MAIL_SMTP_PASSWORD=my_smtp_password

MAIL_SMTP_HOST

  • Description: The host name of the SMTP server.
  • Usage: Specifies the server to connect to for sending emails.
  • Validation: Must be a non-empty string.
  • Example: MAIL_SMTP_HOST=smtp.example.com

MAIL_SMTP_PORT

  • Description: The port number for the SMTP server.
  • Usage: Specifies the port to connect to on the SMTP server.
  • Validation: Must be a non-empty string containing only digits. The value is converted to an integer.
  • Example: MAIL_SMTP_PORT=587

MAIL_SMTP_SSL_ENABLED

  • Description: Indicates whether SSL is enabled for the SMTP connection.
  • Usage: Determines if SSL should be used when connecting to the SMTP server.
  • Validation: Must be a non-empty string with a value of either TRUE or FALSE.
  • Example: MAIL_SMTP_SSL_ENABLED=TRUE

How to Define Environment Variables in Posit Connect Workbench

Click on Varibles in the top right corner of the Posit Connect Workbench:

Screenshot showing the Variables section in the Posit Connect Workbench
Screenshot showing the Variables section in the Posit Connect Workbench

Click in Add variable:

Screenshot showing the Add variable button in the Posit Connect Workbench
Screenshot showing the Add variable button in the Posit Connect Workbench

Specify Name and Value and click Save:

Screenshot showing the dialog to specify Name and Value for a variable in the Posit Connect Workbench
Screenshot showing the dialog to specify Name and Value for a variable in the Posit Connect Workbench

A reminder will be shown that you need to restart the application to apply the changes:

Screenshot showing the reminder to restart the application after saving changes in the Posit Connect Workbench
Screenshot showing the reminder to restart the application after saving changes in the Posit Connect Workbench

You can edit existing variables by clicking on the Edit button:

Screenshot showing the Edit button for existing variables in the Posit Connect Workbench
Screenshot showing the Edit button for existing variables in the Posit Connect Workbench

Change the value and click Save:

Screenshot showing the dialog to change the value of an existing variable in the Posit Connect Workbench
Screenshot showing the dialog to change the value of an existing variable in the Posit Connect Workbench

Finally click on Republish to apply the changes:

Screenshot showing the Republish button to apply changes in the Posit Connect Workbench
Screenshot showing the Republish button to apply changes in the Posit Connect Workbench

Publishing from the Command Line

You can also publish the application from the command line using the rsconnect. The environment variables can be set following these instructions: Environment variables