问题
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