如何关闭闪亮

时间:2016-03-31 10:31:52

标签: r shiny

R' shiny我想创建一个应用程序,其中包含一个函数,用于对用户给出的值进行操作并返回结果(输入数据)。我重写了网上发现的一些例子,并提出了:

library(shiny)
server <- shinyServer(function(input, output, session) {

    values <- reactiveValues()
    values$df <- data.frame(N = numeric(0), A = numeric(0), C = numeric(0))

    newEntry <- observe({

      if(input$update > 0) {
        gr <- 10 + input$n
        newLine <- isolate(c(input$n, input$nr1, gr))
        isolate(values$df[nrow(values$df) + 1,] <- c(input$n, input$nr1, gr))
              }
    })

    output$table1 <- renderTable({values$df})

})

ui <- shinyUI(fluidPage(
  titlePanel("submitButton example"),
  fluidRow(
    column(3, wellPanel(
      sliderInput("nr1", "Give a number: ",  min = 0, max = 100, value = 0, step = 2),

      sliderInput("n", "N:", min = 10, max = 1000, value = 200,
                  step = 10),

      actionButton("update", "Update Table")

    )),
    column(6,
           tableOutput("table1")    
    )
  )
))
shinyApp(ui, server)

这几乎是我想要的,除了在第一次点击Update Table按钮后,应用程序更新表值而不等待下一次点击。如何应对?

1 个答案:

答案 0 :(得分:2)

这应该有效

rm(list = ls())
library(shiny)
server <- shinyServer(function(input, output, session) {

  values <- reactiveValues()
  values$df <- data.frame(N = numeric(0), A = numeric(0), C = numeric(0))

  newEntry <- observeEvent(input$update,{
    gr <- 10 + input$n
    values$df[nrow(values$df) + 1,] <- c(input$n, input$nr1, gr)
  })
  output$table1 <- renderTable({values$df})
})

ui <- shinyUI(fluidPage(
  titlePanel("submitButton example"),
  fluidRow(
    column(3, wellPanel(
      sliderInput("nr1", "Give a number: ",  min = 0, max = 100, value = 0, step = 2),
      sliderInput("n", "N:", min = 10, max = 1000, value = 200, step = 10),
      actionButton("update", "Update Table"))),
    column(6, tableOutput("table1"))
  )
))
shinyApp(ui, server)