Add columns to a reactive data frame in Shiny and update them

后端 未结 2 1196
无人及你
无人及你 2021-01-05 22:16

I would like to be able to calculate a new column of data based on dividing one column by another, with both original columns selected by a user input. I would like to have

2条回答
  •  有刺的猬
    2021-01-05 22:19

    You don't return anything in your reactive for selectedData2 you just do an incrementation <-, I think you should do this :

       function(input, output, session) {
    
      # Combine the selected input variables into a new data frame
      selectedData <- reactive({
        return(iris[, c(input$xcol, input$ycol),])
      })
    
    
      # divide one variable selection by the other
      selectedData2 <- reactive({
                new<-iris[, c(input$xcol)]/iris[, c(input$ycol)]
                return(new)
    
        })
    
      # create data output for selected variables
      output$view <- renderTable({selectedData()
      })
    
      # create data output for calculated variable
      output$view2 <- renderTable({selectedData2()
      })
    
    }
    

提交回复
热议问题