2014-06-12 72 views
2

我讀過的話題,它是不可能重新閃亮的包的actionButton的價值,但我找不到任何伎倆來解決我的問題。actionButton在RShiny:替代重置價值

我想刪除在主面板中的文本和按鈕,此代碼:

library(shiny) 

shinyUI(fluidPage(

    titlePanel("Trying to reset text !"), 

    sidebarLayout(
     sidebarPanel(
      actionButton("button1","Print text") 
     ), 

     mainPanel(
      textOutput("textToPrint"), 
      br(), 
      uiOutput("uiButton2") 
     ) 
    ) 
)) 

shinyServer(function(input, output) { 

    output$textToPrint <- renderText({ 
     if(input$button1==0) (return("")) 
     else (return("Button clicked")) 
    }) 

    output$uiButton2 <- renderUI({ 
     if(input$button1==0) (return()) 
     else (return(actionButton("button2","Reset text and this button"))) 
    }) 

}) 

什麼是替代不可能輸入$按鈕1 = 0

預先感謝您的幫助,

馬特

回答

3

感謝鄭元暢,這裏是這樣做的一個很好的方法:

shinyServer(function(input, output) { 
    values <- reactiveValues(shouldShow = FALSE) 

    observe({ 
     if (input$button1 == 0) return() 
     values$shouldShow = TRUE 
    }) 

    observe({ 
     if (is.null(input$button2) || input$button2 == 0) 
      return() 
     values$shouldShow = FALSE 
    }) 

    output$textToPrint <- renderText({ 
     if (values$shouldShow) 
      "Button clicked" 
    }) 
    output$uiButton2 <- renderUI({ 
     if (values$shouldShow) 
      actionButton("button2","Reset text and this button") 

    }) 
})