Insert a numeric input for each row - R Shiny

江枫思渺然 提交于 2019-12-02 00:26:22

You can bind your matrix with two vectors of strings of the HTML tags for numeric inputs (input1 and input2 in my code bellow), and add the sanitize.text.function to evaluate the HTML tags as is (and not as strings).

For example :

shiny::runApp(list(
  ui = basicPage(
    tableOutput("My_table")
  ),
  server = function(input, output, session) {

    My_table = matrix( 
      c(1:100), 
      nrow=20, 
      ncol=5)

    output$My_table <- renderTable({
      input1 <- paste0("<input id='a", 1:nrow(My_table), "' class='shiny-bound-input' type='number' style='width: 50px;'>")
      input2 <- paste0("<input id='b", 1:nrow(My_table), "' class='shiny-bound-input' type='number' style='width: 50px;'>")
      cbind(input1, My_table, input2)
    }, sanitize.text.function = function(x) x)

  }
))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!