Insert a numeric input for each row - R Shiny

后端 未结 1 876
刺人心
刺人心 2021-01-22 21:54

I have a complex code that generates a big matrix, but here I attach a simple, reproducible example in order to explain clearly what I want: Here\'s the code:

#          


        
相关标签:
1条回答
  • 2021-01-22 22:02

    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)
    
      }
    ))
    
    0 讨论(0)
提交回复
热议问题