我已经阅读了有关使用Shiny Package重置actionButton值的主题,但我找不到任何解决问题的技巧.
我想用以下代码删除主面板中的文本和按钮:
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")))
})
})
Run Code Online (Sandbox Code Playgroud)
什么是不可能的输入$ button1 = 0的替代方案?
在此先感谢您的帮助,
马特
感谢Joe Cheng,这是一个很好的方法:
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")
})
})
Run Code Online (Sandbox Code Playgroud)