【问题标题】:Display selectInput and sliderInput values on action button click在操作按钮单击时显示 selectInput 和 sliderInput 值
【发布时间】:2017-04-11 17:09:54
【问题描述】:

创建了一个应用程序,我想从用户那里获取滑块输入和选择输入,并在我们单击操作按钮时显示它。最初,当我们运行应用程序代码时工作正常,但是当我们更改 sliderInput 和 selectInput 中的值时,输出会自动显示而无需单击按钮。

shinyUI(fluidPage(

  # Application title

titlePanel("Old Faithful Geyser Data"),

  # Sidebar

  sidebarLayout(

sidebarPanel(
      sliderInput("tm", "select the interval", min = 0, max = 20,value = 10),
      selectInput("samples", label = "Select the sample type", c("Sample A","Sample B","Sample C")),
      actionButton("act", label = " Update" )
      ),


    mainPanel(
      textOutput("val"),
      br(),
      textOutput("sam")
    )
  )
))

shinyServer(function(input, output) {

  observe(
    if(input$act>0){
  output$val <- renderText(
    paste("You selected the value" ,input$tm)
    )

  output$sam <- renderText(input$samples)

    }
   )
})

我只想在单击操作按钮时更改值。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您可以将输出值设为eventReactive,而不是observe

    这里是服务器端代码(因为在 ui 端没有任何改变)。

    shinyServer(function(input, output) {
    
      val = eventReactive(input$act, {
        paste("You selected the value" ,input$tm)
      })
    
      sam = eventReactive(input$act, {
        input$samples
      })
    
      output$val = renderText( 
        val()
        )
      output$sam = renderText(
        sam()
      )
    })
    

    【讨论】:

      猜你喜欢
      • 2018-10-09
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-14
      • 2017-08-19
      • 2021-04-07
      相关资源
      最近更新 更多