代码之家  ›  专栏  ›  技术社区  ›  SNT

如果用户输入已在shiny app中运行,则替换基于输出表的

  •  0
  • SNT  · 技术社区  · 7 年前

    shinyApp(
    ui = basicPage(
      mainPanel(
        numericInput("model_input", label = h5("Total Budget"), value = 9000000),
        numericInput("iterations", label = h5("Iterations"), value = 900),
        actionButton("run", "Run"),
        actionButton("reset", "reset"),
        tableOutput("view")
      )
    ),
    server = function(input, output) {
      runcar<- reactive({
        mtcars %>% mutate(new = mpg * input$model_input +input$iterations)
             })
      output$view <- renderTable({
        mtcars
      })
    }
    

    0 回复  |  直到 7 年前
        1
  •  1
  •   tigerloveslobsters    7 年前

    library(dplyr)
    library(shiny)
    
    shinyApp(
      ui = basicPage(
        mainPanel(
          numericInput("model_input", label = h5("Total Budget"), value = 9000000),
          numericInput("iterations", label = h5("Iterations"), value = 900),
          actionButton("run", "Run"),
          actionButton("reset", "reset"),
          tableOutput("view")
        )
      ),
      server = function(input, output) {
        v <- reactiveValues(data = mtcars)  # this makes sure that on load, your default data will show up
    
        observeEvent(input$run, {
          v$data <- mtcars %>% mutate(new = mpg * input$model_input +input$iterations)
        })
    
        observeEvent(input$reset, {
          v$data <- mtcars # your default data
         })  
    
        output$view <- renderTable({
          v$data
        })
      }
    )
    
    推荐文章