【问题标题】:Display output table in shiny based on user inputs and reset to default table根据用户输入以闪亮的方式显示输出表并重置为默认表
【发布时间】:2019-07-06 14:21:00
【问题描述】:

我有一个闪亮的应用程序,在加载时我想显示一个默认表。现在,一旦加载应用程序,用户就可以更改输入中的值,一旦单击运行按钮,当前表应该根据用户输入替换为新表。一旦完成,如果用户单击重置按钮,它应该再次显示默认表。我怎样才能做到这一点。以下是基本应用程序

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
  })
}

)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    我认为下面的解决方案应该可以解决您的问题。

    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
        })
      }
    )
    

    【讨论】:

      猜你喜欢
      • 2015-06-06
      • 2016-12-09
      • 2020-06-23
      • 2015-08-11
      • 2020-07-26
      • 1970-01-01
      • 2020-07-07
      • 2016-06-01
      • 2015-05-15
      相关资源
      最近更新 更多