Rating Stars in R shiny app

旧巷老猫 提交于 2019-12-10 23:16:00

问题


I am trying to add some elements to my shiny app to make it look better. Therefore, I am using the new shiny.semantic package which allows to add semantic UI elements in an easy way. One finds examples for shiny semantic elements here: http://demo.appsilondatascience.com/shiny.semantic/components/

I wanted to add a rating stars UI with the following code:

library(shiny)
#devtools::install_github("Appsilon/shiny.semantic")
library(shiny.semantic)

ui <- function() {
  shinyUI(
    semanticPage(
      title = "My page",
      suppressDependencies("bootstrap"),
      div(class = "ui star rating")
    )
  )
}

server <- shinyServer(function(input, output) {
})

shinyApp(ui = ui(), server = server)

Unfortunately, the rating stars are not appearing in the app. Is there another way to add such rating stars to shiny apps?


回答1:


You need to initialize with Javascript code

ui.R:

library(shiny)
library(shiny.semantic)

shinyUI(semanticPage(
  shinyjs::useShinyjs(),
  div(class = "ui star rating")
))

server.R:

library(shiny)
library(shinyjs)
jsCode <- "
$('.ui.rating')
  .rating({
    initialRating: 3,
    maxRating: 5
  })
;
"

shinyServer(function(input, output) {
  runjs(jsCode)
})


来源:https://stackoverflow.com/questions/44893336/rating-stars-in-r-shiny-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!