2016-11-28 74 views
0

创建一个应用程序,我在其中使用sliderInput并从用户&中选择输入,当我们单击动作按钮时显示它。当我们运行应用程序代码时,运行良好,但是当我们更改滑块输入&中的值时,无需单击按钮即可自动显示selectInput输出。在动作按钮上单击显示selectInput和sliderInput值单击

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) 

    } 
    ) 
}) 

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

回答

1

而不是observe,您可以使您的输出值为eventReactive

这里是服务器端代码(因为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() 
) 
})