Skip to content

Commit

Permalink
Merge pull request #16 from shahronak47/14-multiple-stars
Browse files Browse the repository at this point in the history
Allow possibility to include multiple shinyRatings without disturbing each other
  • Loading branch information
shahronak47 authored Jul 4, 2023
2 parents 0248b17 + 154e3f6 commit 88e13f3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinyRatings
Title: An intuitive way of providing star rating on a shiny app
Version: 0.0.2
Version: 0.0.3
Authors@R: person("Ronak", "Shah", , "[email protected]", role = c("aut", "cre"))
Description: An intuitive way of providing star rating on a shiny app.
License: MIT + file LICENSE
Expand Down
20 changes: 12 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# shinyRatings 0.0.3

- [Add more than 1 shinyRating without disturbing each other](#15)

# shinyRatings 0.0.2

* Add a disabled argument in `shinyRatings` function.
* [Allow possibility of variable number of stars](https://github.com/shahronak47/shinyRatings/issues/9)
* [Add default value of starts selected](https://github.com/shahronak47/shinyRatings/issues/9)
- Add a disabled argument in `shinyRatings` function.
- [Allow possibility of variable number of stars](https://github.com/shahronak47/shinyRatings/issues/9)
- [Add default value of starts selected](https://github.com/shahronak47/shinyRatings/issues/9)

# shinyRatings 0.0.1

* [Fix center alignment of all the elements](https://github.com/shahronak47/shinyRatings/issues/11)
* [Value and stars aligned](https://github.com/shahronak47/shinyRatings/issues/3)
* [Add tests](https://github.com/shahronak47/shinyRatings/issues/5)
* Initial and most basic version of the package
* Added a `NEWS.md` file to track changes to the package.
- [Fix center alignment of all the elements](https://github.com/shahronak47/shinyRatings/issues/11)
- [Value and stars aligned](https://github.com/shahronak47/shinyRatings/issues/3)
- [Add tests](https://github.com/shahronak47/shinyRatings/issues/5)
- Initial and most basic version of the package
- Added a `NEWS.md` file to track changes to the package.
16 changes: 8 additions & 8 deletions R/shinyRatings.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ shinyRatings <- function(inputId, no_of_stars = 5, default = no_of_stars, disabl
),
htmltools::tags$body(
shiny::div(id = inputId, class = "shinyRatings",
htmltools::HTML(ratings_html(no_of_stars, disabled)), data = jsonlite::toJSON(list(n = calculate_def))
htmltools::HTML(ratings_html(no_of_stars, disabled, inputId)), data = jsonlite::toJSON(list(n = calculate_def))
)
)
)
}

#' @noRd
ratings_html <- function(n, disabled) {
ratings_html <- function(n, disabled, inputId) {
half_num <- seq(0.5, n, 1)
full_num <- seq(1, n, 1)
half_num_chr <- sub('.', '', half_num, fixed = TRUE)
full_num_chr <- paste0(full_num, '0')

dynamic_html <- paste0(
dynamic_html <- paste0(
sprintf(
'<label aria-label="%s stars" class="rating__label rating__label--half" for="rating2-%s"><i class="rating__icon--star fa fa-star-half"></i></label>
<input class="rating__input" name="rating2" id="rating2-%s" value="%s" type="radio">
<label aria-label="%s star" class="rating__label" for="rating2-%s"><i class="rating__icon--star fa fa-star"></i></label>
<input class="rating__input" name="rating2" id="rating2-%s" value="%s" type="radio">',
half_num, half_num_chr, half_num_chr, half_num, full_num, full_num_chr, full_num_chr, full_num
'<label aria-label="%s stars" class="rating__label rating__label--half" for="%s-%s"><i class="rating__icon--star fa fa-star-half"></i></label>
<input class="rating__input" name="%s" id="%s-%s" value="%s" type="radio">
<label aria-label="%s star" class="rating__label" for="%s-%s"><i class="rating__icon--star fa fa-star"></i></label>
<input class="rating__input" name="%s" id="%s-%s" value="%s" type="radio">',
half_num, inputId, half_num_chr, inputId, inputId, half_num_chr, half_num, full_num, inputId, full_num_chr, inputId, inputId, full_num_chr, full_num
), collapse = '')

if(isTRUE(disabled)) {
Expand Down
2 changes: 1 addition & 1 deletion inst/exdata/shinyRatingsBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $.extend(shinyRatingsInputBinding, {
$(el).find("input").each(function(inputitem){
count = count + 1
if(count <= n) {
$(this).prop("checked", "true");
$(this).prop("checked", true);
}
});
},
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-shinyRatings.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("shinyRatings works", {
})

test_that("ratings_html works", {
res <- ratings_html(5, disabled = FALSE)
res <- ratings_html(5, disabled = FALSE, "abc")
expect_type(res, 'character')
expect_s3_class(htmltools::HTML(res), 'html')
})
Expand Down

0 comments on commit 88e13f3

Please sign in to comment.