Skip to content

Commit

Permalink
updates for 0.0.2 CRAN release
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinoa committed Dec 20, 2016
1 parent 4553e35 commit 839881c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: shinyFeedback
Type: Package
Title: Displays User Feedback Next to Shiny Inputs
Version: 0.0.1.9000
Date: 2016-12-12
Version: 0.0.2
Date: 2016-12-19
Authors@R: person("Andy", "Merlino", email = "[email protected]", role =
c("aut", "cre"))
Description: Easily display user feedback next to Shiny inputs. The feedback message is displayed when the feedback condition evaluates to TRUE.
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# shinyFeedback 0.0.1.9000
# shinyFeedback 0.0.2

- support for `shiny::selectInput()`
- feedback messages are not longer displayed for non supported `shiny::*Input()`s
- support for multiple feedbacks for a single shiny input
- Font Awesome icons can now be used

# shinyFeedback 0.0.1

Expand Down
33 changes: 18 additions & 15 deletions inst/srcjs/checkFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
// the Shiny input.
//
// @param message
// @param $el the element that the feedback us being displayed around.
// @param $label input label
// @param $group input group
// @param $eInput the input element
// @param $eLabel the label element
// @param $egroup the form-group element
//
function feedbackHandler(message, $el, $label, $group) {
function feedbackHandler(message, $eInput, $eLabel, $eGroup) {
var inp = inputs[message.inputId];

function removeFeedback() {

$label.css("color", "#333");
$el.removeAttr("style");
$eLabel.css("color", "#333");
$eInput.removeAttr("style");
if (message.icon) {
$("#" + message.inputId + "-icon").remove();
$group.removeClass("has-feedback");
$eGroup.removeClass("has-feedback");
}
if (message.text) {
$("#" + message.inputId + "-text").remove();
Expand All @@ -75,15 +75,18 @@
inp.toggle(message.feedbackId);

// display feedback
$label.css("color", message.color);
$el.css("border", "1px solid " + message.color);
if (message.color) {
$eLabel.css("color", message.color);
$eInput.css("border", "1px solid " + message.color);
}

if (message.text) {
$("<div id='" + message.inputId + "-text' class='col-xs-12'><p style='color: " + message.color +"; margin-top: 0px;'>"+ message.text +"</p></div><br id='" + message.inputId + "-spacing'/>").insertAfter($el);
$("<div id='" + message.inputId + "-text' class='col-xs-12'><p style='color: " + message.color +"; margin-top: 0px;'>"+ message.text +"</p></div><br id='" + message.inputId + "-spacing'/>").insertAfter($eInput);
}

if (message.icon) {
$group.addClass("has-feedback");
$("<span id='" + message.inputId + "-icon' class='form-control-feedback' style='color: " + message.color + ";'>" + message.icon + "</span>").insertAfter($el);
$eGroup.addClass("has-feedback");
$("<span id='" + message.inputId + "-icon' class='form-control-feedback' style='color: " + message.color + ";'>" + message.icon + "</span>").insertAfter($eInput);
}
}
}
Expand All @@ -99,13 +102,13 @@
function feedbackSelectize(message) {
var $input = findInput(message.inputId);
var $label = $input.parent().siblings("label");
var $formGroup = $input.parent().eq(1);
var $formGroup = $input.parent();

// the SELECT html tag does not actually contain the input that is displayed
// find the the displayed input box here
var $inputDisplayed = $input
.siblings(".selectize-control")
.children(".selectize-input");
.find(".selectize-input");

feedbackHandler(message, $inputDisplayed, $label, $formGroup);
}
Expand All @@ -114,7 +117,7 @@
function feedbackSelect(message) {
var $input = findInput(message.inputId);
var $label = $input.parent().siblings("label");
var $formGroup = $input.parent().eq(1);
var $formGroup = $input.parent();

feedbackHandler(message, $input, $label, $formGroup);
}
Expand Down
9 changes: 5 additions & 4 deletions vignettes/shinyFeedback-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ vignette: >

## Functionality

The `shinyFeedback` package creates a user friendly message that appears along side a `shiny` input. A feedback message is shown when the `shiny` input's value meets some condition. Here are pictures of a few `shiny` inputs with `feeback` messages displayed:
The `shinyFeedback` package creates a user friendly message that appears along side a `shiny` input. Here are pictures of `shiny` inputs with feeback messages displayed:

![](feedback-screenshot.png)

Expand Down Expand Up @@ -66,22 +66,23 @@ The above app uses the `feedbackWarning()` function to display a default warning

## The `feedback` function

The primary function provided by `shinyFeedback` is `feedback()`. `feedback()` allows you to set feedback message color, icons, and text. The feedback is displayed when the expression supplied to the `condition` argument evaluates to TRUE.
The primary function provided by `shinyFeedback` is `feedback()`. `feedback()` creates messages similar to those shown in the image at the top of this vignette. The color, icon, and text of the feedback message can be customized.

To use `feedback()`, you will want to call it from inside a `shiny` observer (either `shiny::observe()` or `shiny::observeEvent()`).

## Handy `feedback` wrappers

`shinyFeedback` has 3 convenient wrappers functions:

- `feedbackWarning()`
- `feedbackDanger()`
- `feedbackSuccess()`

The above functions provide default arguments for all the formal arguments in the `feedback` function other than `inputId` and `condition`. A live app using these function is available [here](https://merlinoa.shinyapps.io/shinyfeedbackapp/).
The above functions provide default arguments for all the formal arguments in the `feedback` function other than `inputId` and `condition`. A live app using these functions is available [here](https://merlinoa.shinyapps.io/shinyfeedbackapp/).

## Multiple `feedback`s

When assigning multiple `feedback()`s to a single input, place the `feedback()`s in the same `shiny` observer. The `feedback()`s further down in the body of the observer will override the higher `feedback()`s if multiple `feedback()` function conditions evaluate to TRUE.
When assigning multiple `feedback()`s to a single input (e.g. you want to display a certain feedback message if the input value >= 1, and a different feedback value if the input is >= 2), place the `feedback()`s in the same `shiny` observer. The `feedback()`s further down in the body of the observer will override the higher `feedback()`s if multiple `feedback()` function conditions evaluate to TRUE.

```{r, eval = FALSE}
ui <- fluidPage(
Expand Down

0 comments on commit 839881c

Please sign in to comment.