Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/julianschmocker/shinyChatR
A R Shiny Chat Module. This package provides a reusable chat module for R Shiny apps. The module allows multiple users to connect to a common chat and send messages to each other in real-time.
https://github.com/julianschmocker/shinyChatR
Last synced: 3 months ago
JSON representation
A R Shiny Chat Module. This package provides a reusable chat module for R Shiny apps. The module allows multiple users to connect to a common chat and send messages to each other in real-time.
- Host: GitHub
- URL: https://github.com/julianschmocker/shinyChatR
- Owner: julianschmocker
- License: gpl-3.0
- Created: 2023-02-23T10:02:41.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-28T19:52:17.000Z (11 months ago)
- Last Synced: 2024-05-14T10:31:29.656Z (6 months ago)
- Language: R
- Homepage: https://julianschmocker.github.io/shinyChatR/
- Size: 4.06 MB
- Stars: 23
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
- awesome-shiny-extensions - shinyChatR - Reusable chat module for Shiny apps. Allows sending messages and view messages from other users. Messages can be stored in a database or a `.rds` file. (UI Components / Chat)
- jimsghstars - julianschmocker/shinyChatR - A R Shiny Chat Module. This package provides a reusable chat module for R Shiny apps. The module allows multiple users to connect to a common chat and send messages to each other in real-time. (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# shinyChatR
[![Test coverage](https://github.com/julianschmocker/shinyChatR/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/julianschmocker/shinyChatR/actions/workflows/test-coverage.yaml)
This package provides a reusable chat module for R Shiny apps. The module allows multiple users to connect to a common chat and send messages to each other in real-time.
The messages can either be stored in a database or a rds data. Here is an example of the UI:
![](https://github.com/julianschmocker/shinyChatR/blob/master/vignettes/figures/example_chat2.png?raw=true){width=460}
## Features
* Real-time chat: messages are sent and received in real-time, without the need to refresh the page. It is possible to specify how often the data source should be read.
* Multiple users: multiple users can connect to the chat room and send messages to each other.
* Persistent messages: chat messages are stored in a database or rds file, allowing them to be retrieved and viewed even after a user logs out or the app is closed.## General Usage
To use the chat module in your own Shiny app, follow these steps:
1. Install the package
2. Load the package `library("shinyChatR")`
3. Initialize the database table or rds file
4. Add chat module to the appThe details of the different steps can be found below:
## Database connection for storing chat data
If you are using a database connection to store the chat messages, you will need to initialize the database table before using the chat module. The following example shows an example how to do this using the `DBI` and `RSQLite` packages. Replace `db_file` with the path to your database file. The data will be saved in the table `chat_data`.
```{r, eval = FALSE}
library(DBI)
library(RSQLite)db_file <- "path_to_your_database_file"
conn <- dbConnect(RSQLite::SQLite(), db_file)```
If the table does not yet exist, it will be created in the specified connection. Now you can add the chat module to your app:
```{r, eval = FALSE}
library(shinyChatR)
ui <- fluidPage(
chat_ui("test")
)server <- function(input, output, server) {
chat_server("test", db_connection = conn,
db_table_name = "chat_data",
chat_user = "user1")
}# Run the application
shinyApp(ui = ui, server = server)
```## RDS file for storing chat data
A similar approach is required for rds data.
```{r, eval = FALSE}
df <- data.frame(rowid = numeric(),
user = character(),
text = character(),
time = double())#
test_rds <- "path_to_rds_file.rds"
saveRDS(df, test_rds)
```It is not necessary to initiate the rds file. It will be created if it does not exist.
Now you can add the chat module to your app:```{r, eval = FALSE}
library(shinyChatR)
test_rds <- "path_to_rds_file.rds"ui <- fluidPage(
chat_ui("test2")
)server <- function(input, output, server) {
chat_server("test2",
rds_path = test_rds,
chat_user = "user2")
}# Run the application
shinyApp(ui = ui, server = server)
```## Installation
Install from CRAN with
```{r, eval = FALSE}
install.packages("shinyChatR")
```You can install the development version of shinyChatR from
[GitHub](https://github.com/julianschmocker/shinyChatR) with:```{r, eval = FALSE}
remotes::install_github("julianschmocker/shinyChatR")
```