diff --git a/DESCRIPTION b/DESCRIPTION index 9a28d6b..c3de9b6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "shahronak47@yahoo.in", role = c("aut", "cre")) Description: An intuitive way of providing star rating on a shiny app. License: MIT + file LICENSE diff --git a/NEWS.md b/NEWS.md index 4ba1094..7fd3047 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/shinyRatings.R b/R/shinyRatings.R index 825a14c..fe357c9 100644 --- a/R/shinyRatings.R +++ b/R/shinyRatings.R @@ -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( - ' - - -', - half_num, half_num_chr, half_num_chr, half_num, full_num, full_num_chr, full_num_chr, full_num + ' + + + ', + 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)) { diff --git a/inst/exdata/shinyRatingsBinding.js b/inst/exdata/shinyRatingsBinding.js index 4f13975..e31742f 100644 --- a/inst/exdata/shinyRatingsBinding.js +++ b/inst/exdata/shinyRatingsBinding.js @@ -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); } }); }, diff --git a/tests/testthat/test-shinyRatings.R b/tests/testthat/test-shinyRatings.R index 7f892f7..424e4cb 100644 --- a/tests/testthat/test-shinyRatings.R +++ b/tests/testthat/test-shinyRatings.R @@ -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') })