1

I would like to generate sliders in my server (because the number of sliders I need depend on other inputs). As you will see with the code herebelow and the picture, the sliders that appear do not look good. I presume it has to do with the way I specify them in HTML (maybe something to do with the style/css?).

Here is the code:

ui <- pageWithSidebar(
headerPanel("test"),
sidebarPanel(
helpText('these sliders do not look good:')  
),

mainPanel(uiOutput('slider'))
)

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

output$slider <- renderTable({  
inputs <- paste0("<input id='Sl_C", 1:2, "' class='jslider-pointer jslider-pointer-to'   type = 'range' value='c(0,20)' min='0' max='100'>")  

matrix <- data.frame(inputs)   
},sanitize.text.function = function(x) x)

}

runApp(list(ui=ui,server=server))

Any advice/suggestion would be highly appreciated.

All the bestenter image description here

user1431694
  • 715
  • 1
  • 11
  • 22
  • Shiny has its own `sliderInput`, that looks very pretty out of the box. Any reason you are using `jSlider`? – Ramnath Mar 08 '14 at 20:36
  • it's just that I need to create many sliders, and I need to give them different id's. For that reason, I though about using paste0() and creating in HMTL. But is there another way to produce different sliders with differents ID's (and values possibly) in the server ? Many thanks – user1431694 Mar 08 '14 at 20:38
  • OK, I think I've found a way, based on the following post:http://stackoverflow.com/questions/19130455/create-dynamic-number-of-input-elements-with-r-shiny. Sorry for the repetitive question, I don't know why I did not find it earlier – user1431694 Mar 08 '14 at 20:47

1 Answers1

3

Here is one way to achieve multiple slider inputs.

library(shiny)
multiSliders = function(n, ...){
  sliders = lapply(1:n, function(i){
    sliderInput(paste0('slider-', i),  paste('Slider', i), ...)
  })
  paste_all = function(...) paste(..., collapse = '\n')
  HTML(do.call('paste_all', sliders))
}

runApp(list(
  ui = pageWithSidebar(
    headerPanel('Multiple Sliders'),
    sidebarPanel(
      sliderInput('slider-0', 'Slider0', 0, 10, 4),
      multiSliders(2, 0, 10, 4)
    ),
    mainPanel()
  ),
  server = function(input, output){

  }

))
Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • Hi, actually the reason why I need to use html is to embed them in a matrix. If I use inputs <- lapply(1:2, function(i) sliderInput(inputId = paste0("sl", i), label = "", min = 0, max =100, value = 50)), in my code above, I obtain the following error: cannot coerce class “”shiny.tag“” to a data.frame. By any chance, have you got by any idea on how to fix this ? Many thanks – user1431694 Mar 09 '14 at 14:37
  • I am not sure I follow your question. Can you post a link to the code that you are trying, that gives you this errors? – Ramnath Mar 09 '14 at 16:38
  • Hi, I posted the question here http://stackoverflow.com/questions/22283095/r-shiny-how-to-embed-sliderinputs-selectinputs-and-radiobuttons-in-a-data-frame – user1431694 Mar 09 '14 at 20:49
  • Hi Ramnath (and thanks for your help) I've found the answer and posted it after my question in the link above. Cheers – user1431694 Mar 10 '14 at 16:14