2017-05-01 61 views
0

我試圖初始化按鈕被點擊時有光澤的輸出圖,這意味着按下按鈕時輸出圖將從屏幕上刪除,但我不知道確切的命令。我試過類似:刪除有光澤的輸出圖

observedEvent(input$button, { output$plot1 <- NULL }) 

但它不起作用。 希望你能幫助,

感謝

回答

0

而不是刪除的情節,您可以showhideshinyjs

rm(list=ls()) 
library(shiny) 
library(shinyjs) 

ui <- fluidPage(
    useShinyjs(), 
    sidebarPanel(actionButton("button", "Hide Plot1"), 
       actionButton("button2", "Show Plot1"),br(), 
       actionButton("button3", "Hide Plot2"), 
       actionButton("button4", "Show Plot2")), 
    mainPanel(plotOutput("plot1"),plotOutput("plot2")) 
) 

server <- function(input, output, session) { 
    observeEvent(input$button, { 
    hide("plot1") 
    }) 
    observeEvent(input$button2, { 
    show("plot1") 
    }) 
    observeEvent(input$button3, { 
    hide("plot2") 
    }) 
    observeEvent(input$button4, { 
    show("plot2") 
    }) 

    output$plot1 <- renderPlot({ 
    hist(mtcars$mpg) 
    }) 
    output$plot2 <- renderPlot({ 
    hist(mtcars$qsec) 
    }) 

} 
shinyApp(ui, server)