Package 'shinyslack'

Title: Integrate Slack and Shiny
Description: Login to Shiny apps using Slack, and use Slack information in those apps.
Authors: Jon Harmon [aut, cre]
Maintainer: Jon Harmon <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9010
Built: 2024-11-17 04:55:51 UTC
Source: https://github.com/r4ds/shinyslack

Help Index


Check Slack Login

Description

Confirm that a user is logged into Slack.

Usage

check_login(
  team_id,
  session = shiny::getDefaultReactiveDomain(),
  shinyslack_key = Sys.getenv("SHINYSLACK_KEY")
)

Arguments

team_id

The Slack team ID through which the user is being authenticated.

session

The shiny session object. The default shiny::getDefaultReactiveDomain() is likely always sufficient outside of tests.

shinyslack_key

(optional) A key to use to encrypt the string. If not set, the string is returned unencrypted.

Value

A shiny::reactive() which returns a logical indicating whether the user is logged in with proper API access.


Get the current team_id

Description

The team_id is set when an app is launched. In almost all cases, that value is the one you will want for any instances of team_id.

Usage

get_shinyslack_team_id()

set_shinyslack_team_id(team_id)

Arguments

team_id

The Slack team ID through which the user is being authenticated.

Value

A string representing the team_id.

Examples

# If no app is active, the team_id will be a zero-length character vector.
get_shinyslack_team_id()

set_shinyslack_team_id("T123456")
get_shinyslack_team_id()

Launch a Shiny App with a Slack Login

Description

Launch a shiny::shinyApp() with an integrated Slack login.

Usage

shinyslack_app(
  ui,
  server,
  team_id,
  ...,
  expiration = 90,
  shinyslack_key = Sys.getenv("SHINYSLACK_KEY")
)

Arguments

ui

A 0- or 1-argument function defining the UI of a Shiny app, or a shiny::tagList().

server

A function with three parameters: input, output, and session. The function is called once for each session ensuring that each app is independent.

team_id

The Slack team ID through which the user is being authenticated.

...

Additional parameters passed on to shiny::shinyApp().

expiration

Days after which the cookie should expire. To remove an HttpOnly cookie, send a negative value for this attribute.

shinyslack_key

(optional) A key to use to encrypt the string. If not set, the string is returned unencrypted.

Value

An object that represents the app. See shiny::shinyApp() for details.


Fetch Slack User Info

Description

Get information about the logged-in user from the Slack API.

Usage

user_info(
  components = c("user_id", "real_name", "display_name", "pronouns", "user_name"),
  session = shiny::getDefaultReactiveDomain(),
  slack_api_key = session$userData$shinyslack_api_key,
  team_id = get_shinyslack_team_id(),
  shinyslack_key = Sys.getenv("SHINYSLACK_KEY")
)

Arguments

components

A character vector of user components to include. Current options are:

  • user_id: The ID used to uniquely identify this user on this Slack team.

  • real_name: The full name of this user as entered in their profile.

  • display_name: The name that the user has chosen to display to other users in Slack.

  • pronouns: The pronouns set by this user, if any.

  • user_name: You probably do not want this. It is a legacy piece of information.

session

The shiny session object. The default shiny::getDefaultReactiveDomain() is likely always sufficient outside of tests.

slack_api_key

The Slack API key to use. The default value should likely always be used outside of tests.

team_id

The Slack team ID through which the user is being authenticated.

shinyslack_key

(optional) A key to use to encrypt the string. If not set, the string is returned unencrypted.

Value

A shiny::reactive() with a named character vector.