Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [object Object]
- require(shiny)
- in.df <- data.frame(name = c("Alice","Bob","Charles"),
- age = c(22, 25, 36))
- rownames(in.df) <- NULL
- runApp(
- list(
- ui = fluidPage(
- sidebarPanel(
- numericInput("line", "Line number", value = 1),
- textInput("name", "Name:"),
- numericInput("age", "Age:", value = 25),
- actionButton("amendButton", "Amend an entry")
- ),
- mainPanel(
- tableOutput("table"))
- ),
- server = function(input, output, session){
- values <- reactiveValues()
- values$df <- in.df
- current_line <- reactive({
- il <- input$line
- nr <- nrow(values$df)
- if(il > nr){
- return(nr)
- } else if(il <= 0){
- return(1)
- } else{
- return(il)
- }
- })
- amendData <- observe({
- if(input$amendButton > 0){
- newLine <- isolate(c(input$name, input$age))
- values$df <- isolate(values$df[- current_line(), ])
- isolate(values$df <- rbind(as.matrix(values$df), unlist(newLine)))
- values$df <- values$df[order(values$df[,1]),]
- }
- })
- observe({
- updateTextInput(session = session,
- inputId = 'name',
- value = values$df[unlist( current_line()),1]
- )
- updateNumericInput(session = session,
- inputId = 'age',
- value = values$df[unlist( current_line()),2]
- )
- updateNumericInput(session = session ,
- inputId = 'line',
- value = current_line()
- )
- })
- output$table <- renderTable(values$df )
- }
- )
- )
- addData <- observe({
- if(input$appendButton > 0){
- newLine <- isolate(c(input$name, input$age))
- isolate(values$df <- rbind(as.matrix(values$df), unlist(newLine)))
- values$df <- values$df[order(values$df[,1]),]
- }
- })
- values$df <- isolate(values$df[- current_line(), ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement