How can I construct a table result using "eventReactive" in shiny

1

How can I create a "table result" for each relationship I chose in the selectInput "Col" and "Row"? Dinamicaly, for each time you press the 'ok' button.

library(shiny)
shinyUI(fluidPage(
  h4("Give a valor between 0 to 5, to each col/row relationship"),
  hr(),
  uiOutput("colrow"),
  hr(),
  h5("Result:"),
  tableOutput("result")
))
shinyServer(function(input, output, session) {
  cols <<- c("Select"="", "col01" = "c01", "col02" = "c02")
  rows <<- c("Select"="", "row01" = "r01", "row02" = "r02")
  values <<- c("Select"="", 1:5)

output$colrow <- renderUI({
  div(selectInput("ipt_col", label = "Col",
                  choices = c(cols),
                  selected = cols[1],
                  width = "50%"),
      selectInput("ipt_row", label = "Row",
                  choices = c(rows),
                  selected = rows[1],
                  width = "50%"),
      selectInput("ipt_vlr", label = "Value",
                  choices = c(values),
                  selected = ""),
      hr(),
      actionButton("bt_ok", "ok")
  )
})

colrow_vlr <- eventReactive(input$bt_ok, {      
  as.data.frame(matrix(input$ipt_vlr, 1,1, dimnames = list(input$ipt_row,input$ipt_col)))
})

output$result <- renderTable({
  colrow_vlr()
})
})
    
asked by anonymous 15.03.2018 / 16:54

1 answer

1

Let me get this straight. Do you want to fill in the table?

(0) top

      c01    c02
r01 
r02 

(1) Col = 'col02'; Row = 'row01' and Value = 1 --- > ok

      c01    c02
r01            1
r02 

(2) Col = 'col01'; Row = 'row02' and Value = 5 --- > ok

      c01    c02
r01            1
r02     5

And so on?

Because the code now only produces:

(0) top

 ... 

(1) Col = 'col02'; Row = 'row01' and Value = 1 --- > ok

c02
 1 

(2) Col = 'col01'; Row = 'row02' and Value = 5 --- > ok

c01 
  5

But if your problem was just making the line number appear in the table then use the option rownames=TRUE of renderTable() :

output$result <- renderTable(colrow_vlr(),rownames = TRUE)

This results in the following:

    
22.03.2018 / 19:51