Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daattali/shinybrowser
π Find out information about a user's web browser in Shiny apps
https://github.com/daattali/shinybrowser
r r-package rstats shiny shiny-r
Last synced: 12 days ago
JSON representation
π Find out information about a user's web browser in Shiny apps
- Host: GitHub
- URL: https://github.com/daattali/shinybrowser
- Owner: daattali
- License: other
- Created: 2021-01-09T20:15:29.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-18T18:44:43.000Z (3 months ago)
- Last Synced: 2024-10-14T09:45:54.554Z (24 days ago)
- Topics: r, r-package, rstats, shiny, shiny-r
- Language: R
- Homepage: https://daattali.com/shiny/shinybrowser-demo/
- Size: 122 KB
- Stars: 40
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - daattali/shinybrowser - π Find out information about a user's web browser in Shiny apps (R)
README
shinybrowser
π Find out information about a user's web browser in Shiny apps
Demo
Β·
by Dean Attali---
{shinybrowser} lets you easily detect a user's web browser information in Shiny apps.
The available information is: browser name (such as "Chrome" or "Safari") and version, device type (mobile or desktop), operating system (such as "Windows" or "Mac" or "Android") and version, and browser dimensions. See the [demo Shiny app](https://daattali.com/shiny/shinybrowser-demo/) online for an example.
**Need Shiny help? [I'm available for consulting](https://attalitech.com/).**
**If you find {shinybrowser} useful, please consider [supporting my work](https://github.com/sponsors/daattali)! β€**> This package is part of a larger ecosystem of packages with a shared vision: solving common Shiny issues and improving Shiny apps with minimal effort, minimal code changes, and clear documentation. Other packages for your Shiny apps:
| Package | Description | Demo |
|---|---|---|
| [shinyjs](https://deanattali.com/shinyjs/) | π‘ Easily improve the user experience of your Shiny apps in seconds | [π](https://deanattali.com/shinyjs/overview#demo) |
| [shinyalert](https://github.com/daattali/shinyalert/) | π―οΈ Easily create pretty popup messages (modals) in Shiny | [π](https://daattali.com/shiny/shinyalert-demo/) |
| [shinyscreenshot](https://github.com/daattali/shinyscreenshot/) | π· Capture screenshots of entire pages or parts of pages in Shiny apps | [π](https://daattali.com/shiny/shinyscreenshot-demo/) |
| [timevis](https://github.com/daattali/timevis/) | π Create interactive timeline visualizations in R | [π](https://daattali.com/shiny/timevis-demo/) |
| [shinycssloaders](https://github.com/daattali/shinycssloaders/) | β Add loading animations to a Shiny output while it's recalculating | [π](https://daattali.com/shiny/shinycssloaders-demo/) |
| [colourpicker](https://github.com/daattali/colourpicker/) | π¨ A colour picker tool for Shiny and for selecting colours in plots | [π](https://daattali.com/shiny/colourInput/) |
| [shinydisconnect](https://github.com/daattali/shinydisconnect/) | π Show a nice message when a Shiny app disconnects or errors | [π](https://daattali.com/shiny/shinydisconnect-demo/) |
| [shinytip](https://github.com/daattali/shinytip/) | π¬ Simple flexible tooltips for Shiny apps | WIP |
| [shinymixpanel](https://github.com/daattali/shinymixpanel/) | π Track user interactions with Mixpanel in Shiny apps or R scripts | WIP |
| [shinyforms](https://github.com/daattali/shinyforms/) | π Easily create questionnaire-type forms with Shiny | WIP |## Table of contents
- [The problem](#problem)
- [Sponsors π](#sponsors)
- [How to use](#usage)
- [Example](#example)
- [Convenience checker functions](#convenience)
- [Installation](#install)
- [Limitations](#limitations)
- [Accuracy](#accuracy)
- [Supported values](#supported)
- [Mobile vs desktop vs tablet](#device_type)
- [Width and height](#dimensions)The Problem
When building a Shiny app for other users, sometimes you might want to know some information about the user's browser and system. A few scenarios where this can be useful:
1. Your Shiny app is using an advanced browser functionality that isn't supported in Internet Explorer. If a user views your app on Internet Explorer, you want to show them a warning message.
2. Your app displays some text to the user and you want to show them a message with the keyboard shortcut for copying the text to their clipboard. You need to know whether the user is on Windows or Mac to decide what keyboard shortcut to use (ctrl+C vs command+C).
3. Your app contains a plot with a legend. If the user is on a wide enough screen, you want the legend to appear beside the plot, but if the screen is too narrow then you want the legend to appear below the plot.In these situations, you want to detect information about the user's browser type (scenario 1), operating system (scenario 2), or browser dimensions (scenario 3).
{shinybrowser} gives you easy access to this information.
Sponsors π
Developing and maintaining many packages takes a lot of time. Please consider sponsoring this work!
> There are no sponsors yet
[Become the first sponsor for
{shinybrowser}\!](https://github.com/sponsors/daattali/sponsorships?tier_id=39856)How to use
First you need to call `detect()` anywhere in the UI. This will initialize {shinybrowser}, run the script that attempts to detect all the user information, and send it to Shiny.
Then you can use any of the {shinybrowser} functions to inquire about the user. You can use `get_browser()`/`get_browser_version()` to get the browser name and version, `get_os()`/`get_os_version()` to get the operating system, `get_device()` to find out if the user is on mobile or desktop, and `get_width()`/`get_height()` to find out the browser dimensions.
All these values are reactive, so they must be accessed inside an `observe()`/`reactive()` or similar.
Example
To see what {shinybrowser} returns for your system, check the [demo Shiny app](https://daattali.com/shiny/shinybrowser-demo/).
A simple example of using {shinybrowser} is below:
```
library(shiny)ui <- fluidPage(
shinybrowser::detect()
)server <- function(input, output, session) {
observe({
str(shinybrowser::get_all_info())
})
}shinyApp(ui, server)
```This app will print all the information retrieved by {shinybrowser} to your console. Notice that it's calling `get_all_info()`, which is a way to get all the information in one list instead of using the individual `get_*` functions.
On my current machine, the output from the app is:
```
List of 5
$ device : chr "Desktop"
$ browser :List of 2
..$ name : chr "Chrome"
..$ version: chr "87"
$ os :List of 2
..$ name : chr "Windows"
..$ version: chr "10"
$ dimensions:List of 2
..$ width : int 1920
..$ height: int 937
$ user_agent: chr "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
```Note that {shinybrowser} also returns the "user_agent" string, which you can access using `get_user_agent()`, but you generally shouldn't need to use this string.
You can also use {shinybrowser} in Rmarkdown documents, as long as they use `runtime: shiny`.
Convenience checker functions
{shinybrowser} has a few convenience functions for very common checks. For example, there are many browsers, but often Internet Explorer is the problematic one. If you want to check for it you can use `is_browser_ie()`, which is just a shorthand for `get_browser() == "Internet Explorer"`. There are a few other similar `is_*` functions that can be used as a shortcut.
Installation
**For most users:** To install the stable CRAN version:
```r
install.packages("shinybrowser")
```**For advanced users:** To install the latest development version from GitHub:
```r
install.packages("remotes")
remotes::install_github("daattali/shinybrowser")
```Limitations
Accuracy
It's important to understand there is no reliable way to detect the information in {shinybrowser} with 100% accuracy.
{shinybrowser} makes a best effort at identifying the most accurate information, but some browser/operating system combinations may be difficult to identify. Users can also use a variety of tools to deliberately spoof this information.
With that in mind, {shinybrowser} should detect the correct information in most cases.
Supported values
Only major browsers and operating systems are supported, which means that the RStudio Viewer may result in an "UNKNOWN" browser, and unpopular operating systems may also result in "UNKNOWN". An operating system version is only detectable for Windows and for Mac OS X; all other operating systems will have an "UNKNOWN" version.
Mobile vs desktop vs tablet
For device type, {shinybrowser} attempts to detect whether a device is "mobile" or "desktop". The distinction between mobile and desktop is not always clear, so if what you actually care about is the size of the device, it might be better to use `get_width()`.
Tablets return ambiguous results; some tablets self-report as mobile devices while others as desktop.
Width and height
The width and height of the browser window are only reported once, when the `detect()` function is initially called. If the user resizes the browser window, the new dimensions are not reported until the page is refreshed.
Credits
Logo design by [Alfredo HernΓ‘ndez](https://aldomann.com/).