Shiny widgets in DT TabledateInput not working on DT in shinyAdd table row in jQueryR shiny mouseover text for table columnsHow to Add edit delete of table in shiny appConnecting values of sliderInput in ShinyLink the max sliderInput value to the max value within a table columnSliderInput issue with table in R shinyDynamic Shiny InputIncorrect columnname displayed in dataTableOutput, when selectinput(multiple=T) - shinyShiny widgets do not work unless another widget is activatedDynamically render choropleth map with sliderInput in R shiny

Is there any common country to visit for persons holding UK and Schengen visas?

Make a Bowl of Alphabet Soup

Did I make a mistake by ccing email to boss to others?

Can a Knock spell open the door to Mordenkainen's Magnificent Mansion?

"Oh no!" in Latin

Is there a distance limit for minecart tracks?

Comic-book: Kids find a dead female superhero in the woods

What properties make a magic weapon befit a Rogue more than a DEX-based Fighter?

Sort with assumptions

Does capillary rise violate hydrostatic paradox?

Why doesn't Gödel's incompleteness theorem apply to false statements?

Asserting that Atheism and Theism are both faith based positions

A seasonal riddle

Why would five hundred and five same as one?

python displays `n` instead of breaking a line

How do you justify more code being written by following clean code practices?

What is it called when someone votes for an option that's not their first choice?

How to get directions in deep space?

Why is "la Gestapo" feminine?

Recursively move files within sub directories

Was Woodrow Wilson really a Liberal?

Why didn’t Eve recognize the little cockroach as a living organism?

Toggle window scroll bar

Started in 1987 vs. Starting in 1987



Shiny widgets in DT Table


dateInput not working on DT in shinyAdd table row in jQueryR shiny mouseover text for table columnsHow to Add edit delete of table in shiny appConnecting values of sliderInput in ShinyLink the max sliderInput value to the max value within a table columnSliderInput issue with table in R shinyDynamic Shiny InputIncorrect columnname displayed in dataTableOutput, when selectinput(multiple=T) - shinyShiny widgets do not work unless another widget is activatedDynamically render choropleth map with sliderInput in R shiny













1















I'm trying to include shiny widgets such as textInput, selectInput (single), sliderInput, and selectInput (multiple) in the rows of a DT table. When the widgets are directly on the page, they display correctly, however, when they are put in the table, some of them do not display correctly.



The textInput is fine and the selectInput (single) is mostly fine save for some css differences, but the selectInput (multiple) isn't displaying correctly and the sliderInput definitely isn't displaying correctly. It seems the widgets that rely on javascript are the ones that have issues. Is there a way to make these widgets work correctly in the DT table?



Here is my reproducible example. I used the raw HTML for the widgets when putting them in the table, but I took that directly from the HTML generated by the shiny functions for each widget.



library(shiny)
library(DT)

ui <- fluidPage(
h3("This is how I want the widgets to look in the DT table."),
fluidRow(column(3, textInput(inputId = "text",
label = "TEXT")),
column(3, selectInput(inputId = "single_select",
label = "SINGLE SELECT",
choices = c("", "A", "B", "C"))),
column(3, sliderInput(inputId = "slider",
label = "SLIDER",
min = 0,
max = 10,
value = c(0, 10))),
column(3, selectizeInput(inputId = "multiple_select",
label = "MULTIPLE SELECT",
choices = c("", "A", "B", "C"),
multiple = TRUE))),
h3("This is how they actually appear in a DT table."),
fluidRow(DTOutput(outputId = "table"))
)

server <- function(input, output, session)

output$table <- renderDT(
data <- data.frame(ROW = 1:5,
TEXT = '<input id="text" type="text" class="form-control" value=""/>',
SINGLE_SELECT = '<select id="single_select" style="width: 100%;">
<option value="" selected></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>',
SLIDER = '<input class="js-range-slider" id="slider" data-type="double" data-min="0" data-max="10" data-from="0" data-to="10" data-step="1" data-grid="true" data-grid-num="10" data-grid-snap="false" data-prettify-separator="," data-prettify-enabled="true" data-keyboard="true" data-drag-interval="true" data-data-type="number"/>',
MULTIPLE_SELECT = '<select id="multiple_select" class="form-control" multiple="multiple">
<option value=""></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>',
stringsAsFactors = FALSE)

datatable(data = data,
selection = "none",
escape = FALSE,
rownames = FALSE)
)



shinyApp(ui = ui, server = server)









share|improve this question


























    1















    I'm trying to include shiny widgets such as textInput, selectInput (single), sliderInput, and selectInput (multiple) in the rows of a DT table. When the widgets are directly on the page, they display correctly, however, when they are put in the table, some of them do not display correctly.



    The textInput is fine and the selectInput (single) is mostly fine save for some css differences, but the selectInput (multiple) isn't displaying correctly and the sliderInput definitely isn't displaying correctly. It seems the widgets that rely on javascript are the ones that have issues. Is there a way to make these widgets work correctly in the DT table?



    Here is my reproducible example. I used the raw HTML for the widgets when putting them in the table, but I took that directly from the HTML generated by the shiny functions for each widget.



    library(shiny)
    library(DT)

    ui <- fluidPage(
    h3("This is how I want the widgets to look in the DT table."),
    fluidRow(column(3, textInput(inputId = "text",
    label = "TEXT")),
    column(3, selectInput(inputId = "single_select",
    label = "SINGLE SELECT",
    choices = c("", "A", "B", "C"))),
    column(3, sliderInput(inputId = "slider",
    label = "SLIDER",
    min = 0,
    max = 10,
    value = c(0, 10))),
    column(3, selectizeInput(inputId = "multiple_select",
    label = "MULTIPLE SELECT",
    choices = c("", "A", "B", "C"),
    multiple = TRUE))),
    h3("This is how they actually appear in a DT table."),
    fluidRow(DTOutput(outputId = "table"))
    )

    server <- function(input, output, session)

    output$table <- renderDT(
    data <- data.frame(ROW = 1:5,
    TEXT = '<input id="text" type="text" class="form-control" value=""/>',
    SINGLE_SELECT = '<select id="single_select" style="width: 100%;">
    <option value="" selected></option>
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
    </select>',
    SLIDER = '<input class="js-range-slider" id="slider" data-type="double" data-min="0" data-max="10" data-from="0" data-to="10" data-step="1" data-grid="true" data-grid-num="10" data-grid-snap="false" data-prettify-separator="," data-prettify-enabled="true" data-keyboard="true" data-drag-interval="true" data-data-type="number"/>',
    MULTIPLE_SELECT = '<select id="multiple_select" class="form-control" multiple="multiple">
    <option value=""></option>
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
    </select>',
    stringsAsFactors = FALSE)

    datatable(data = data,
    selection = "none",
    escape = FALSE,
    rownames = FALSE)
    )



    shinyApp(ui = ui, server = server)









    share|improve this question
























      1












      1








      1


      1






      I'm trying to include shiny widgets such as textInput, selectInput (single), sliderInput, and selectInput (multiple) in the rows of a DT table. When the widgets are directly on the page, they display correctly, however, when they are put in the table, some of them do not display correctly.



      The textInput is fine and the selectInput (single) is mostly fine save for some css differences, but the selectInput (multiple) isn't displaying correctly and the sliderInput definitely isn't displaying correctly. It seems the widgets that rely on javascript are the ones that have issues. Is there a way to make these widgets work correctly in the DT table?



      Here is my reproducible example. I used the raw HTML for the widgets when putting them in the table, but I took that directly from the HTML generated by the shiny functions for each widget.



      library(shiny)
      library(DT)

      ui <- fluidPage(
      h3("This is how I want the widgets to look in the DT table."),
      fluidRow(column(3, textInput(inputId = "text",
      label = "TEXT")),
      column(3, selectInput(inputId = "single_select",
      label = "SINGLE SELECT",
      choices = c("", "A", "B", "C"))),
      column(3, sliderInput(inputId = "slider",
      label = "SLIDER",
      min = 0,
      max = 10,
      value = c(0, 10))),
      column(3, selectizeInput(inputId = "multiple_select",
      label = "MULTIPLE SELECT",
      choices = c("", "A", "B", "C"),
      multiple = TRUE))),
      h3("This is how they actually appear in a DT table."),
      fluidRow(DTOutput(outputId = "table"))
      )

      server <- function(input, output, session)

      output$table <- renderDT(
      data <- data.frame(ROW = 1:5,
      TEXT = '<input id="text" type="text" class="form-control" value=""/>',
      SINGLE_SELECT = '<select id="single_select" style="width: 100%;">
      <option value="" selected></option>
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
      </select>',
      SLIDER = '<input class="js-range-slider" id="slider" data-type="double" data-min="0" data-max="10" data-from="0" data-to="10" data-step="1" data-grid="true" data-grid-num="10" data-grid-snap="false" data-prettify-separator="," data-prettify-enabled="true" data-keyboard="true" data-drag-interval="true" data-data-type="number"/>',
      MULTIPLE_SELECT = '<select id="multiple_select" class="form-control" multiple="multiple">
      <option value=""></option>
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
      </select>',
      stringsAsFactors = FALSE)

      datatable(data = data,
      selection = "none",
      escape = FALSE,
      rownames = FALSE)
      )



      shinyApp(ui = ui, server = server)









      share|improve this question














      I'm trying to include shiny widgets such as textInput, selectInput (single), sliderInput, and selectInput (multiple) in the rows of a DT table. When the widgets are directly on the page, they display correctly, however, when they are put in the table, some of them do not display correctly.



      The textInput is fine and the selectInput (single) is mostly fine save for some css differences, but the selectInput (multiple) isn't displaying correctly and the sliderInput definitely isn't displaying correctly. It seems the widgets that rely on javascript are the ones that have issues. Is there a way to make these widgets work correctly in the DT table?



      Here is my reproducible example. I used the raw HTML for the widgets when putting them in the table, but I took that directly from the HTML generated by the shiny functions for each widget.



      library(shiny)
      library(DT)

      ui <- fluidPage(
      h3("This is how I want the widgets to look in the DT table."),
      fluidRow(column(3, textInput(inputId = "text",
      label = "TEXT")),
      column(3, selectInput(inputId = "single_select",
      label = "SINGLE SELECT",
      choices = c("", "A", "B", "C"))),
      column(3, sliderInput(inputId = "slider",
      label = "SLIDER",
      min = 0,
      max = 10,
      value = c(0, 10))),
      column(3, selectizeInput(inputId = "multiple_select",
      label = "MULTIPLE SELECT",
      choices = c("", "A", "B", "C"),
      multiple = TRUE))),
      h3("This is how they actually appear in a DT table."),
      fluidRow(DTOutput(outputId = "table"))
      )

      server <- function(input, output, session)

      output$table <- renderDT(
      data <- data.frame(ROW = 1:5,
      TEXT = '<input id="text" type="text" class="form-control" value=""/>',
      SINGLE_SELECT = '<select id="single_select" style="width: 100%;">
      <option value="" selected></option>
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
      </select>',
      SLIDER = '<input class="js-range-slider" id="slider" data-type="double" data-min="0" data-max="10" data-from="0" data-to="10" data-step="1" data-grid="true" data-grid-num="10" data-grid-snap="false" data-prettify-separator="," data-prettify-enabled="true" data-keyboard="true" data-drag-interval="true" data-data-type="number"/>',
      MULTIPLE_SELECT = '<select id="multiple_select" class="form-control" multiple="multiple">
      <option value=""></option>
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
      </select>',
      stringsAsFactors = FALSE)

      datatable(data = data,
      selection = "none",
      escape = FALSE,
      rownames = FALSE)
      )



      shinyApp(ui = ui, server = server)






      javascript r datatable shiny dt






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 0:58









      mosk915mosk915

      99118




      99118






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Sliders



          For the sliders, you have to start with a text input:



          SLIDER = '<input type="text" id="s" name="slider" value="" />'


          and then turn it into a slider with JavaScript:



          js <- c(
          "function(settings)",
          " $('#s').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          See ionRangeSlider for the options.



          You can pass the JavaScript code with the initComplete option:



          server <- function(input, output, session) 

          output$table <- renderDT(
          data <- data.frame(ROW = 1:5,
          TEXT = '<input id="text" type="text" class="form-control" value=""/>',
          SINGLE_SELECT = '<select id="single_select" style="width: 100%;">
          <option value="" selected></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          SLIDER = '<input type="text" id="s" name="slider" value="" />',
          MULTIPLE_SELECT = '<select id="multiple_select" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          stringsAsFactors = FALSE)

          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js)
          ))
          )




          Then you get the slider for the first row only:



          enter image description here



          That's because the five text inputs have the same id. You have to set a different id for the five text inputs:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="" />', i)
          ),


          Then use this JavaScript code to turn them into sliders:



          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          enter image description here



          To set the initial values of from and to, it's better to give them in the value argument of the input text like this:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="5;15" />', i)
          )

          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          ""
          )


          Multiple selects



          To get the desired display of a multiple select, you have to call selectize():



          MULTIPLE_SELECT = '<select id="mselect" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>'
          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          " $('#mselect').selectize()",
          ""
          )


          Similarly, this applies to the first multiple select only. Use individual id's to apply to the five ones.



          Binding



          Finally, you have to bind the inputs to get their value available in Shiny:



          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js),
          preDrawCallback = JS('function() Shiny.unbindAll(this.api().table().node()); '),
          drawCallback = JS('function() Shiny.bindAll(this.api().table().node()); ')
          )
          )


          Now you can get the values in input$Slider1, input$Slider2, ..., and input$mselect. Note that input$Slider[1/2/3/4/5] returns the values of the slider in this format: "3;15".






          share|improve this answer

























          • Thanks! This is exactly what I needed. I think I'm going to want to have a date range input as well but I think I can figure out how to do that based on how you did these.

            – mosk915
            Mar 8 at 4:48






          • 1





            @mosk915 See here for the date input.

            – Stéphane Laurent
            Mar 8 at 7:02











          • Perfect, thanks again!

            – mosk915
            Mar 8 at 18:33











          • I have one follow up question if you don't mind. How hard would it be to make the slider appear in a dropdown, similar to the way it appears in a column filter for a numeric column where you see a text box and then the slider drops down below the box when you click in it?

            – mosk915
            Mar 8 at 22:00











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034483%2fshiny-widgets-in-dt-table%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Sliders



          For the sliders, you have to start with a text input:



          SLIDER = '<input type="text" id="s" name="slider" value="" />'


          and then turn it into a slider with JavaScript:



          js <- c(
          "function(settings)",
          " $('#s').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          See ionRangeSlider for the options.



          You can pass the JavaScript code with the initComplete option:



          server <- function(input, output, session) 

          output$table <- renderDT(
          data <- data.frame(ROW = 1:5,
          TEXT = '<input id="text" type="text" class="form-control" value=""/>',
          SINGLE_SELECT = '<select id="single_select" style="width: 100%;">
          <option value="" selected></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          SLIDER = '<input type="text" id="s" name="slider" value="" />',
          MULTIPLE_SELECT = '<select id="multiple_select" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          stringsAsFactors = FALSE)

          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js)
          ))
          )




          Then you get the slider for the first row only:



          enter image description here



          That's because the five text inputs have the same id. You have to set a different id for the five text inputs:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="" />', i)
          ),


          Then use this JavaScript code to turn them into sliders:



          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          enter image description here



          To set the initial values of from and to, it's better to give them in the value argument of the input text like this:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="5;15" />', i)
          )

          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          ""
          )


          Multiple selects



          To get the desired display of a multiple select, you have to call selectize():



          MULTIPLE_SELECT = '<select id="mselect" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>'
          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          " $('#mselect').selectize()",
          ""
          )


          Similarly, this applies to the first multiple select only. Use individual id's to apply to the five ones.



          Binding



          Finally, you have to bind the inputs to get their value available in Shiny:



          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js),
          preDrawCallback = JS('function() Shiny.unbindAll(this.api().table().node()); '),
          drawCallback = JS('function() Shiny.bindAll(this.api().table().node()); ')
          )
          )


          Now you can get the values in input$Slider1, input$Slider2, ..., and input$mselect. Note that input$Slider[1/2/3/4/5] returns the values of the slider in this format: "3;15".






          share|improve this answer

























          • Thanks! This is exactly what I needed. I think I'm going to want to have a date range input as well but I think I can figure out how to do that based on how you did these.

            – mosk915
            Mar 8 at 4:48






          • 1





            @mosk915 See here for the date input.

            – Stéphane Laurent
            Mar 8 at 7:02











          • Perfect, thanks again!

            – mosk915
            Mar 8 at 18:33











          • I have one follow up question if you don't mind. How hard would it be to make the slider appear in a dropdown, similar to the way it appears in a column filter for a numeric column where you see a text box and then the slider drops down below the box when you click in it?

            – mosk915
            Mar 8 at 22:00
















          2














          Sliders



          For the sliders, you have to start with a text input:



          SLIDER = '<input type="text" id="s" name="slider" value="" />'


          and then turn it into a slider with JavaScript:



          js <- c(
          "function(settings)",
          " $('#s').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          See ionRangeSlider for the options.



          You can pass the JavaScript code with the initComplete option:



          server <- function(input, output, session) 

          output$table <- renderDT(
          data <- data.frame(ROW = 1:5,
          TEXT = '<input id="text" type="text" class="form-control" value=""/>',
          SINGLE_SELECT = '<select id="single_select" style="width: 100%;">
          <option value="" selected></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          SLIDER = '<input type="text" id="s" name="slider" value="" />',
          MULTIPLE_SELECT = '<select id="multiple_select" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          stringsAsFactors = FALSE)

          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js)
          ))
          )




          Then you get the slider for the first row only:



          enter image description here



          That's because the five text inputs have the same id. You have to set a different id for the five text inputs:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="" />', i)
          ),


          Then use this JavaScript code to turn them into sliders:



          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          enter image description here



          To set the initial values of from and to, it's better to give them in the value argument of the input text like this:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="5;15" />', i)
          )

          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          ""
          )


          Multiple selects



          To get the desired display of a multiple select, you have to call selectize():



          MULTIPLE_SELECT = '<select id="mselect" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>'
          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          " $('#mselect').selectize()",
          ""
          )


          Similarly, this applies to the first multiple select only. Use individual id's to apply to the five ones.



          Binding



          Finally, you have to bind the inputs to get their value available in Shiny:



          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js),
          preDrawCallback = JS('function() Shiny.unbindAll(this.api().table().node()); '),
          drawCallback = JS('function() Shiny.bindAll(this.api().table().node()); ')
          )
          )


          Now you can get the values in input$Slider1, input$Slider2, ..., and input$mselect. Note that input$Slider[1/2/3/4/5] returns the values of the slider in this format: "3;15".






          share|improve this answer

























          • Thanks! This is exactly what I needed. I think I'm going to want to have a date range input as well but I think I can figure out how to do that based on how you did these.

            – mosk915
            Mar 8 at 4:48






          • 1





            @mosk915 See here for the date input.

            – Stéphane Laurent
            Mar 8 at 7:02











          • Perfect, thanks again!

            – mosk915
            Mar 8 at 18:33











          • I have one follow up question if you don't mind. How hard would it be to make the slider appear in a dropdown, similar to the way it appears in a column filter for a numeric column where you see a text box and then the slider drops down below the box when you click in it?

            – mosk915
            Mar 8 at 22:00














          2












          2








          2







          Sliders



          For the sliders, you have to start with a text input:



          SLIDER = '<input type="text" id="s" name="slider" value="" />'


          and then turn it into a slider with JavaScript:



          js <- c(
          "function(settings)",
          " $('#s').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          See ionRangeSlider for the options.



          You can pass the JavaScript code with the initComplete option:



          server <- function(input, output, session) 

          output$table <- renderDT(
          data <- data.frame(ROW = 1:5,
          TEXT = '<input id="text" type="text" class="form-control" value=""/>',
          SINGLE_SELECT = '<select id="single_select" style="width: 100%;">
          <option value="" selected></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          SLIDER = '<input type="text" id="s" name="slider" value="" />',
          MULTIPLE_SELECT = '<select id="multiple_select" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          stringsAsFactors = FALSE)

          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js)
          ))
          )




          Then you get the slider for the first row only:



          enter image description here



          That's because the five text inputs have the same id. You have to set a different id for the five text inputs:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="" />', i)
          ),


          Then use this JavaScript code to turn them into sliders:



          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          enter image description here



          To set the initial values of from and to, it's better to give them in the value argument of the input text like this:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="5;15" />', i)
          )

          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          ""
          )


          Multiple selects



          To get the desired display of a multiple select, you have to call selectize():



          MULTIPLE_SELECT = '<select id="mselect" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>'
          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          " $('#mselect').selectize()",
          ""
          )


          Similarly, this applies to the first multiple select only. Use individual id's to apply to the five ones.



          Binding



          Finally, you have to bind the inputs to get their value available in Shiny:



          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js),
          preDrawCallback = JS('function() Shiny.unbindAll(this.api().table().node()); '),
          drawCallback = JS('function() Shiny.bindAll(this.api().table().node()); ')
          )
          )


          Now you can get the values in input$Slider1, input$Slider2, ..., and input$mselect. Note that input$Slider[1/2/3/4/5] returns the values of the slider in this format: "3;15".






          share|improve this answer















          Sliders



          For the sliders, you have to start with a text input:



          SLIDER = '<input type="text" id="s" name="slider" value="" />'


          and then turn it into a slider with JavaScript:



          js <- c(
          "function(settings)",
          " $('#s').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          See ionRangeSlider for the options.



          You can pass the JavaScript code with the initComplete option:



          server <- function(input, output, session) 

          output$table <- renderDT(
          data <- data.frame(ROW = 1:5,
          TEXT = '<input id="text" type="text" class="form-control" value=""/>',
          SINGLE_SELECT = '<select id="single_select" style="width: 100%;">
          <option value="" selected></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          SLIDER = '<input type="text" id="s" name="slider" value="" />',
          MULTIPLE_SELECT = '<select id="multiple_select" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>',
          stringsAsFactors = FALSE)

          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js)
          ))
          )




          Then you get the slider for the first row only:



          enter image description here



          That's because the five text inputs have the same id. You have to set a different id for the five text inputs:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="" />', i)
          ),


          Then use this JavaScript code to turn them into sliders:



          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20,",
          " from: 5,",
          " to: 15",
          " );",
          ""
          )


          enter image description here



          To set the initial values of from and to, it's better to give them in the value argument of the input text like this:



          SLIDER = sapply(1:5, function(i) 
          sprintf('<input type="text" id="Slider%d" name="slider" value="5;15" />', i)
          )

          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          ""
          )


          Multiple selects



          To get the desired display of a multiple select, you have to call selectize():



          MULTIPLE_SELECT = '<select id="mselect" class="form-control" multiple="multiple">
          <option value=""></option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          </select>'
          js <- c(
          "function(settings)",
          " $('[id^=Slider]').ionRangeSlider(",
          " type: 'double',",
          " grid: true,",
          " grid_num: 10,",
          " min: 0,",
          " max: 20",
          " );",
          " $('#mselect').selectize()",
          ""
          )


          Similarly, this applies to the first multiple select only. Use individual id's to apply to the five ones.



          Binding



          Finally, you have to bind the inputs to get their value available in Shiny:



          datatable(data = data,
          selection = "none",
          escape = FALSE,
          rownames = FALSE,
          options =
          list(
          initComplete = JS(js),
          preDrawCallback = JS('function() Shiny.unbindAll(this.api().table().node()); '),
          drawCallback = JS('function() Shiny.bindAll(this.api().table().node()); ')
          )
          )


          Now you can get the values in input$Slider1, input$Slider2, ..., and input$mselect. Note that input$Slider[1/2/3/4/5] returns the values of the slider in this format: "3;15".







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 at 10:47

























          answered Mar 7 at 10:21









          Stéphane LaurentStéphane Laurent

          15.7k75696




          15.7k75696












          • Thanks! This is exactly what I needed. I think I'm going to want to have a date range input as well but I think I can figure out how to do that based on how you did these.

            – mosk915
            Mar 8 at 4:48






          • 1





            @mosk915 See here for the date input.

            – Stéphane Laurent
            Mar 8 at 7:02











          • Perfect, thanks again!

            – mosk915
            Mar 8 at 18:33











          • I have one follow up question if you don't mind. How hard would it be to make the slider appear in a dropdown, similar to the way it appears in a column filter for a numeric column where you see a text box and then the slider drops down below the box when you click in it?

            – mosk915
            Mar 8 at 22:00


















          • Thanks! This is exactly what I needed. I think I'm going to want to have a date range input as well but I think I can figure out how to do that based on how you did these.

            – mosk915
            Mar 8 at 4:48






          • 1





            @mosk915 See here for the date input.

            – Stéphane Laurent
            Mar 8 at 7:02











          • Perfect, thanks again!

            – mosk915
            Mar 8 at 18:33











          • I have one follow up question if you don't mind. How hard would it be to make the slider appear in a dropdown, similar to the way it appears in a column filter for a numeric column where you see a text box and then the slider drops down below the box when you click in it?

            – mosk915
            Mar 8 at 22:00

















          Thanks! This is exactly what I needed. I think I'm going to want to have a date range input as well but I think I can figure out how to do that based on how you did these.

          – mosk915
          Mar 8 at 4:48





          Thanks! This is exactly what I needed. I think I'm going to want to have a date range input as well but I think I can figure out how to do that based on how you did these.

          – mosk915
          Mar 8 at 4:48




          1




          1





          @mosk915 See here for the date input.

          – Stéphane Laurent
          Mar 8 at 7:02





          @mosk915 See here for the date input.

          – Stéphane Laurent
          Mar 8 at 7:02













          Perfect, thanks again!

          – mosk915
          Mar 8 at 18:33





          Perfect, thanks again!

          – mosk915
          Mar 8 at 18:33













          I have one follow up question if you don't mind. How hard would it be to make the slider appear in a dropdown, similar to the way it appears in a column filter for a numeric column where you see a text box and then the slider drops down below the box when you click in it?

          – mosk915
          Mar 8 at 22:00






          I have one follow up question if you don't mind. How hard would it be to make the slider appear in a dropdown, similar to the way it appears in a column filter for a numeric column where you see a text box and then the slider drops down below the box when you click in it?

          – mosk915
          Mar 8 at 22:00




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034483%2fshiny-widgets-in-dt-table%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович