我已经阅读过使用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")))
})
})
什么是不可能的替代输入$ button1 = 0 ?
先谢谢你的帮助,
马特
答案 0 :(得分:5)
感谢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")
})
})