2016-11-28 71 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() 
) 
})