Skip to content

Commit 1769063

Browse files
Merge pull request #23 from davidruvolo51/dev
Refactored JS methods
2 parents fe13a49 + defcf22 commit 1769063

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+967
-1788
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
^config$
2222
^postcss\.config\.js$
2323
^webpack\.config\.js$
24+
^src$
25+
^pkgbump\.config\.json$

.pkgbump.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: browsertools
22
Title: Running Specific JavaScript functions from R
3-
Version: 0.1.8
3+
Version: 0.2.0
44
Authors@R:
55
person(
66
given = "David",

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(add_css)
4-
export(alert)
54
export(as_js_object)
65
export(console_error)
76
export(console_log)

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# browsertools 0.2.0
2+
3+
* Refactored Browsertools methods
4+
* Added new test environment (`dev/prod-app`)
5+
16
# browsertools 0.1.8
27

38
* Switched to Webpack as the application bundler

R/add_css.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#' Adds a css class(es) to an element using id or classname.
44
#'
55
#' @param elem the id or class name of an html element
6-
#' @param css a string containing the class(es) to add to
7-
#' an html element
6+
#' @param css a string or character array containing css classes
87
#'
98
#' @return Adds a css class(es) to an element using id or classname.
109
#'
@@ -17,7 +16,10 @@
1716
#' tags$style(
1817
#' ".blue-text {
1918
#' color: blue;
20-
#' }"
19+
#' }",
20+
#' ".font-size-lg {
21+
#' font-size: 150%;
22+
#' }"
2123
#' )
2224
#' ),
2325
#' tags$main(
@@ -37,7 +39,7 @@
3739
#' observeEvent(input$addCSS, {
3840
#' browsertools::add_css(
3941
#' elem = "#my-text-example",
40-
#' css = "blue-text"
42+
#' css = c("blue-text", "font-size-lg")
4143
#' )
4244
#' })
4345
#' }

R/alert.R

Lines changed: 0 additions & 48 deletions
This file was deleted.

R/console_error.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#' }
2929
#' @references
3030
#' \url{https://developer.mozilla.org/en-US/docs/Web/API/Console/error}
31-
#' @seealso [console_warn()], [console_log()], [console_table()], [alert()]
31+
#' @seealso [console_warn()], [console_log()], [console_table()]
3232
#' @keywords browsertools debugging console
3333
#' @return Sends an error message to the browser's console
3434
#' @export

R/console_log.R

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#' displaying issues.
66
#'
77
#' @param message a message to display
8-
#' @param expand if TRUE arrays/objects will be auto expanded (default: FALSE)
98
#'
109
#' @examples
1110
#' if (interactive()) {
@@ -32,24 +31,20 @@
3231
#' @references
3332
#' \url{https://developer.mozilla.org/en-US/docs/Web/API/Console/log}
3433
#'
35-
#' @seealso [console_error()], [console_table()], [console_warn()], [alert()]
34+
#' @seealso [console_error()], [console_table()], [console_warn()]
3635
#' @keywords browsertools debugging console
3736
#' @return Outputs an object to the browser's console
3837
#'
3938
#' @export
40-
console_log <- function(message, expand = FALSE) {
39+
console_log <- function(message) {
4140

4241
# validate
4342
if (is.null(message)) stop("argument 'message' is undefined")
44-
if (!is.logical(expand)) stop("argument 'expand' must be a logical value")
4543

4644
# send
4745
session <- shiny::getDefaultReactiveDomain()
4846
session$sendCustomMessage(
4947
type = "console_log",
50-
message= list(
51-
message = message,
52-
expand = expand
53-
)
48+
message = message
5449
)
5550
}

R/console_table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#' @references
3232
#' \url{https://developer.mozilla.org/en-US/docs/Web/API/Console/table}
3333
#'
34-
#' @seealso [as_js_object()], [console_log()], [alert()]
34+
#' @seealso [as_js_object()], [console_log()]
3535
#' @keywords browsertools debugging console
3636
#' @return Outputs an object to the browser's console
3737
#'

R/console_warn.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#' @references
3030
#' \url{https://developer.mozilla.org/en-US/docs/Web/API/Console/warn}
3131
#'
32-
#' @seealso [console_error()], [console_log()], [console_table()], [alert()]
32+
#' @seealso [console_error()], [console_log()], [console_table()]
3333
#' @keywords browsertools console warn
3434
#' @return Outputs a warning message to the console
3535
#'

R/enable_attributes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ enable_attributes <- function() {
4949
htmltools::tags$span(
5050
`data-browsertools-indexible` = "true",
5151
class = "browsertools-hidden browsertools-attributes",
52-
`aria-hidden` = "true"
52+
style = "display: none;"
5353
)
5454
}

R/remove_css.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#' Removes a css class(es) to an element using id or classname.
44
#'
55
#' @param elem the id or class name of an html element
6-
#' @param css a string containing the class(es) to remove from
7-
#' an html element
6+
#' @param css a string or character array containing css classes
87
#' @examples
98
#' if (interactive()) {
109
#' library(shiny)

R/toggle_css.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' Toggles a css state of an html element
44
#'
55
#' @param elem the id or class name of an html element
6-
#' @param css a string containing the class to remove from an html element
6+
#' @param css a string or character array containing css classes
77
#'
88
#' @examples
99
#' if (interactive()) {

R/use_browsertools.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use_browsertools <- function() {
2424
htmltools::htmlDependency(
2525
name = "browsertools",
26-
version = "0.1.8",
26+
version = "0.2.0",
2727
src = "browsertools/public/",
2828
package = "browsertools",
2929
script = "browsertools.min.js",

README.md

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ This package contains a series of functions for running JavaScript functions in
1111

1212
## Install
1313

14-
You can install `browsertools` in R using the following command.
14+
You can install the latest release of `browsertools` in R using the following command.
1515

1616
```r
17-
devtools::install_github("davidruvolo51/browsertools")
17+
remotes::install_github("davidruvolo51/browsertools@*release")
1818
```
1919

2020
## Use
@@ -33,36 +33,35 @@ The package offers the following functions.
3333

3434
### Shiny UI
3535

36-
| function | arguments | description |
37-
| :------- | :-------- | :---------- |
38-
| `use_browsertools` | --- | load `browsertools` dependencies into your shiny app (required).
39-
| `enable_attributes` | --- | allows you to access the HTML attributes of an element in the shiny server; Element must have an ID
40-
| `hidden` | `...` | Hide element(s) by default
36+
| function | arguments | description |
37+
|---------------------|-----------|------------------------------------------------------|
38+
| `enable_attributes` | --- | access HTML attributes of an element (`id` required) |
39+
| `hidden` | `...` | Hide element(s) by default |
40+
| `use_browsertools` | --- | load `browsertools` into your shiny app (required) |
4141

4242
### Shiny Server
4343

44-
| function | arguments | description |
45-
| :------- | :-------- | :---------- |
46-
| `add_css` | `elem`, `css` | add a css class to an element
47-
| `alert` | `message` | displays an alert in the browser
48-
| `as_js_object` | `x` | a data.frame to convert to javascript object
49-
| `console_error` | `message` | send an error message to the console
50-
| `console_log` | `message`, `expand` | log values to the browser console
51-
| `console_table` | `data` | a json object to display in the console; use `as_js_object` function to convert your data before passing into the function
52-
| `console_warn` | `message` | send a warning message to the console
53-
| `debug` | --- | prints JavaScript errors in the R console
54-
| `hide_elem` | `elem` | hides an element
55-
| `insert_adjacent_html` | `id`, `html`, `position` | create a new child element(s) to a parent element
56-
| `inner_html` | `elem`, `string`, `delay` | change the inner html of an element
57-
| `inner_text` | `elem`, `string`, `delay` | change the inner text of an element
58-
| `print_elem` | `elem` | print an html element in the R console
59-
| `refresh_page` | --- | trigger a page refresh (`history.go(0)`)
60-
| `remove_css` | `elem`, `css` | remove a css class from an element
61-
| `remove_element` | `elem` | remove an element from the DOM
62-
| `remove_element_attribute` | `elem`, `attr` | remove an attribute from an element
63-
| `set_document_title` | `title`, `append` | change the title of the document
64-
| `set_element_attribute` | `elem`, `attr`, `value` | update an attribute of an element
65-
| `scroll_to` | `x`, `y`, `elem` | scroll to a position in a page or element (default: `0, 0` = top of document)
66-
| `show_elem` | `elem` | show an element
67-
| `toggle_css` | `elem`, `css` | toggle a css class
68-
| `toggle_elem` | `elem` | toggle the state of an element (i.e., hide or show)
44+
| function | arguments | description |
45+
|----------------------------|---------------------------|------------------------------------------|
46+
| `add_css` | `elem`, `css` | add css class(es) |
47+
| `as_js_object` | `x` | convert an R object to javascript object |
48+
| `console_error` | `message` | send an error message to the console |
49+
| `console_log` | `message`, `expand` | log values to the browser console |
50+
| `console_table` | `data` | display R data in the console |
51+
| `console_warn` | `message` | send a warning message to the console |
52+
| `debug` | --- | print JS errors in the R console |
53+
| `hide_elem` | `elem` | hides an element |
54+
| `inner_html` | `elem`, `string`, `delay` | set the inner html of an element |
55+
| `inner_text` | `elem`, `string`, `delay` | set the inner text of an element |
56+
| `insert_adjacent_html` | `id`, `html`, `position` | insert a new child element(s) |
57+
| `print_elem` | `elem` | print an html element in the R console |
58+
| `refresh_page` | --- | trigger a page refresh |
59+
| `remove_css` | `elem`, `css` | remove css class(es) |
60+
| `remove_element_attribute` | `elem`, `attr` | remove an attribute from an element |
61+
| `remove_element` | `elem` | remove an element |
62+
| `scroll_to` | `x`, `y`, `elem` | scroll to a point or element |
63+
| `set_document_title` | `title`, `append` | change the title of the document |
64+
| `set_element_attribute` | `elem`, `attr`, `value` | update an attribute of an element |
65+
| `show_elem` | `elem` | show an element |
66+
| `toggle_css` | `elem`, `css` | toggle css class(es) |
67+
| `toggle_elem` | `elem` | toggle the state of an element |

config/webpack.common.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// FILE: webpack.common.js
33
// AUTHOR: David Ruvolo
44
// CREATED: 2020-09-25
5-
// MODIFIED: 2020-09-25
5+
// MODIFIED: 2020-11-06
66
// PURPOSE: configuration to be used in prod and dev
77
// DEPENDENCIES: see below
88
// STATUS: working
@@ -11,23 +11,23 @@
1111

1212
// load
1313
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
14-
const HtmlWebpackPlugin = require("html-webpack-plugin");
14+
// const HtmlWebpackPlugin = require("html-webpack-plugin");
1515
const webpack = require("webpack");
1616
const path = require("path");
1717

1818
// configuration
1919
module.exports = {
20-
entry: "./inst/browsertools/src/index.js",
20+
entry: "./src/index.js",
2121
output: {
2222
filename: "browsertools.min.js",
2323
path: path.join(__dirname, "..", "inst/browsertools/public/"),
2424
} ,
2525
plugins: [
2626
new webpack.ProgressPlugin(),
2727
new CleanWebpackPlugin(),
28-
new HtmlWebpackPlugin({
29-
title: "browsertools"
30-
})
28+
// new HtmlWebpackPlugin({
29+
// title: "browsertools"
30+
// })
3131
],
3232
module: {
3333
rules: [

dev/dev-app/app.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ library(shiny)
1515
# add resource path
1616
addResourcePath(
1717
"browsertools",
18-
"~/Github/browsertools/inst/browsertools/public"
18+
"~/Github/browsertools/inst/browsertools/public/"
1919
)
2020

2121
# load package functions
@@ -73,7 +73,7 @@ ui <- tagList(
7373
tags$div(id = "square")
7474
)
7575
),
76-
tags$script(src = "browsertools/browsertools.min.js")
76+
tags$script(src = "browsertools/public/browsertools.min.js")
7777
)
7878

7979

0 commit comments

Comments
 (0)