目的:我需要一种将自定义标签(0、0.33、0.66、1)添加到闪亮滑块的方法。我修改了以下帖子中的代码:R Shiny date slider animation by month (currently by day)
问题:如何将当前滑块值传递给 Shiny 对象?我试图用这篇文章修改我的代码但没有成功:http: //ionden.com/a/plugins/ion.rangeslider/demo_interactions.html
请注意,我对 Javascript 非常陌生,我的代码不能包含任何额外的包。
用户界面
# ui
library(shiny)
shinyUI(fluidPage(
br(),
uiOutput("mySlider"),
verbatimTextOutput("myValue"))
)
服务器
# server
x <- c(0,0.33,0.66,1) # slider values
# function to create slider
sliderValues <- function (inputId, values){
sliderTag <- tags$div(
do.call(tags$input, list(type = "single",
id = "inputId",
value = x)),
tags$script(
HTML('$("#mySlider").ionRangeSlider({
grid: true,
values: [0,0.33,0.66,1]});'))
)
dep <- htmltools::htmlDependency(
"ionrangeslider",
"2.1.12",
c(href = "shared/ionrangeslider"),
script = "js/ion.rangeSlider.min.js",
stylesheet = c(
"css/ion.rangeSlider.css",
"css/ion.rangeSlider.skinShiny.css"
))
htmltools::attachDependencies(sliderTag, dep)
}
server <- function(input, output, session) {
output$mySlider <- renderUI({
sliderValues(inputId = "mySlider",
values = x)
})
output$myValue <- renderPrint({
print(as.numeric(unlist(input$mySlider)))
})
}