Git Product home page Git Product logo

shinychatr's Introduction

shinyChatR

Test coverage

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:

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 app

The 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.

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:

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.

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:

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

install.packages("shinyChatR")

You can install the development version of shinyChatR from GitHub with:

remotes::install_github("julianschmocker/shinyChatR")

shinychatr's People

Contributors

julianschmocker avatar ivokwee avatar olivroy avatar

Stargazers

 avatar Daniel Vera avatar  avatar Ali Mhdian avatar  avatar Indranil Gayen avatar George Mwangi avatar Young Sherlock avatar Jimmy Briggs avatar Ricardo Baptista avatar Plamen Rabadzhiyski avatar Johannes Gruber avatar  avatar Lillian Lu avatar  avatar Denis Abdullin avatar Trey Saddler avatar Antoine J.-P. Tixier avatar Owain  gaunders avatar  avatar Freeman Wang avatar Sam Parmar avatar Lars Andersen avatar  avatar Friedrich Pahlke avatar Leo Lee avatar

Watchers

 avatar

shinychatr's Issues

Add update to typed chat

Hi! This is a really useful package and I am excited to be using it. In my use, I have found a possibility for a new feature. I want to be able to update the current typed text by the user (not a sent message). For instance, a prepopulated generic chat that a user would often send trigged by an actionButton(). In base RShiny there is updateTextInput() that enables this for textInput().

Is this something possible to include in a future release?

Clear text input after send

Hi there, I tested the package and noticed the following behaviour. After sending, the text input is not updated/reset. This is not intuitive. Moreover, if I close and reopen the chat module, the text is sent again and appears twice in the chat. Ideally, pressing the send button also resets the text input.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.