This repository contains a plugin for R Shiny that allows users to authenticate using a username and password. The plugin provides both login and registration capabilities.
Note: This package depends on R Storage package. Currently, the storage package provides both odbc and in-memory type data stores.
At the time of writing this README, the package is not available on CRAN. To install the package, you can use the devtools package to either install the package directly from GitHub or Build and Install it locally.
devtools package to install the package directly from Github:devtools::install_github("https://github.com/FlippieCoetser/Authenticate")
git clone https://github.com/FlippieCoetser/Authenticate
.tar.gz file:devtools::build()
install.packages("path/to/Authenticate_0.1.0.tar.gz", repos = NULL, type = "source")
There are two ways to load the plugin: using the library function or using the Authenticate namespace.
library function:Use the library function to load the View, Controller and Orchestrator directly into the R environment.
library(Authenticate)
Authenticate namespace:Directly address the View, Controller and Orchestrator using the Authenticate namespace.
View <- Authenticate::View
Controller <- Authenticate::Controller
Orchestrator <- Authenticate::Orchestrator
You need to seed the storage with some data if you are using the in-memory storage type.
storage instance:configuration <- data.frame()
storage <- configuration |> Storage::Storage(type = "memory")
Seed.Table function takes a single argument: the name of the table to seed.Authenticate::Users |> storage[['Seed.Table']]('User')
Add the View to the UI. See the ui.r file for an example. The View function takes a single argument: the id of the shiny module.
Authenticate::View("user")
Add the Controller to the Server. See the server.r file for an example. The Controller function has four arguments:
user reactive value to store the current user details.title values to set the title of the login and registration modals.debug flag that enables event logging in the console.Authenticate::Controller("user", storage, title = "Login", debug = TRUE)
user <- reactiveVal()
Authenticate::Controller("user", storage, user = user, title = "Login", debug = TRUE)
observeEvent(user[['username']], {
print(user[['username']])
})
Note: After successful login,
session[['userData']][['username']]will also contains currently logged-in user's username.