From 26b3b00ba71fdb0cccb7d750078dce8617372174 Mon Sep 17 00:00:00 2001 From: Ronak Shah Date: Sun, 2 Jul 2023 19:16:44 +0800 Subject: [PATCH 1/5] different star values --- R/shinyRatings.R | 15 ++++++++------- inst/exdata/shinyRatingsBinding.js | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/R/shinyRatings.R b/R/shinyRatings.R index 825a14c..f6c8198 100644 --- a/R/shinyRatings.R +++ b/R/shinyRatings.R @@ -36,28 +36,29 @@ 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, half_num_chr, inputId, half_num_chr, half_num, full_num, full_num_chr, inputId, full_num_chr, full_num ), collapse = '') + if(isTRUE(disabled)) { # Add disabled attribute to input elements dynamic_html <- gsub(' Date: Sun, 2 Jul 2023 20:21:06 +0800 Subject: [PATCH 2/5] change HTML --- R/shinyRatings.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R/shinyRatings.R b/R/shinyRatings.R index f6c8198..fe357c9 100644 --- a/R/shinyRatings.R +++ b/R/shinyRatings.R @@ -51,14 +51,13 @@ ratings_html <- function(n, disabled, inputId) { dynamic_html <- paste0( sprintf( - ' - - - ', - half_num, half_num_chr, inputId, half_num_chr, half_num, full_num, full_num_chr, inputId, 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)) { # Add disabled attribute to input elements dynamic_html <- gsub(' Date: Mon, 3 Jul 2023 08:38:12 +0800 Subject: [PATCH 3/5] fix #14 #15 --- DESCRIPTION | 2 +- NEWS.md | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) 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. From 7751ed5c34ba9695c7c3dd7e85b8b02050a410fd Mon Sep 17 00:00:00 2001 From: Ronak Shah Date: Mon, 3 Jul 2023 08:41:07 +0800 Subject: [PATCH 4/5] fix tests --- tests/testthat/test-shinyRatings.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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') }) From 154e3f68e5738cd7a3deb148f0ed500845a27979 Mon Sep 17 00:00:00 2001 From: Ronak Shah Date: Mon, 3 Jul 2023 09:56:26 +0800 Subject: [PATCH 5/5] remove console.log statement --- inst/exdata/shinyRatingsBinding.js | 1 - 1 file changed, 1 deletion(-) diff --git a/inst/exdata/shinyRatingsBinding.js b/inst/exdata/shinyRatingsBinding.js index de936e6..e31742f 100644 --- a/inst/exdata/shinyRatingsBinding.js +++ b/inst/exdata/shinyRatingsBinding.js @@ -11,7 +11,6 @@ $.extend(shinyRatingsInputBinding, { /* Get default value */ var data = JSON.parse(el.getAttribute('data')); var n = data.n; - console.log(n); /* Manually set the check property to TRUE for default number of stars */ var count = 0 $(el).find("input").each(function(inputitem){