RShiny 中的 actionButton :重置值的替代方案

2024-01-03

我读过有关不可能使用 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")))
    })

})

不可能的替代方案是什么输入$按钮1 = 0 ?

在此先感谢您的帮助,

Matt


感谢 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")

    })
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

RShiny 中的 actionButton :重置值的替代方案 的相关文章

随机推荐