2017-03-26 28 views

回答

1

是的,從@neilfws鏈接的答案是現貨。我下面將它改編爲您的需求(必須瀏覽器中查看,讓JS運行):

library("shiny") 

# expSlider javascript function 
JS.expify <- 
    " 
// function to exponentiate a sliderInput 
function expSlider (sliderId, sci = false) { 
    $('#'+sliderId).data('ionRangeSlider').update({ 
    'prettify': function (num) { return ('2<sup>'+num+'</sup>'); } 
    }) 
}" 

# call expSlider for each relevant sliderInput 
JS.onload <- 
" 
// execute upon document loading 
$(document).ready(function() { 
// wait a few ms to allow other scripts to execute 
setTimeout(function() { 
// include call for each slider 
expSlider('exp_slider', sci = true) 
}, 5)}) 
" 

ui <- fluidPage(
    tags$head(tags$script(HTML(JS.expify))), 
    tags$head(tags$script(HTML(JS.onload))), 

    sliderInput("exp_slider", "Powers of 2 Slider:", 
       min = -5, max = 10, value = 1, step = 1), 

    br(), 

    textOutput("selection") 
) 

server <- function(input, output, session) { 

    output$selection <- reactive({ 
    paste0("Selected power: ", input$exp_slider, "  Value = ", 2^input$exp_slider) 
    }) 
} 

shinyApp(ui, server) 

enter image description here