繁体   English   中英

renderUI受反应值限制

[英]renderUI conditioned by a reactive value

今天,我试图拥有一个renderUI,其形式和内容取决于reactValues的值。 我正在研究ShinydashBoard

在初始状态下,用户将单击按钮,并且renderUI的形式将更改。 如果用户再单击一次,我希望renderUI再次采用初始形式。

这是我的代码:

library(shiny)
library(shinydashboard)

sidebar <- dashboardSidebar(

)

body <- dashboardBody(
  uiOutput("Text2Bis")


)#dashboardBody

header <- dashboardHeader(
  title = list(icon("star-half-o"),"element-R")
  #messages,
  #notifications,
  #tasks
)

ui <- dashboardPage(header, sidebar, body)


server <- function(input, output, session) {

  previewAction <- reactiveValues(temp = F)

  output$Text2Bis <- renderUI({

    if(is.null(input$button)){
      box(width = 12,background = NULL, height = 100,
          actionButton("button","delete")
      )
    }
    else{
      print(input$button)
      if((isolate(input$button %%2)) == 1){
        print(input$button)
        box(width = 12,background = NULL, height = 100,
            actionButton("button","delete")
        )

      }
      else{
        print(input$button)
        box(width = 12,background = NULL, height = 300,
            actionButton("button","save")
        )
      }

    }



  })



}

shinyApp(ui, server)

我不明白为什么我的应用无法正常工作。 看来actionButton仍在重新初始化?

您有解决这个问题的想法吗?

提前非常感谢您!

干杯

是的,我做到了! 这个简单的脚本需要做很多工作!

这是代码:

library(shiny)
library(shinydashboard)

sidebar <- dashboardSidebar(

)

body <- dashboardBody(
  uiOutput("Text2Bis")


)#dashboardBody

header <- dashboardHeader(
  title = list(icon("star-half-o"),"element-R")
  #messages,
  #notifications,
  #tasks
)

ui <- dashboardPage(header, sidebar, body)


server <- function(input, output, session) {

  previewAction <- reactiveValues(temp = 1)

  output$Text2Bis <- renderUI({

    if((previewAction$temp%%2) ==1 ){
      box(width = 12,background = NULL, height = 100,
          actionButton("save","save")

      )
    }
    else{

      box(width = 12,background = NULL, height = 200,
          actionButton("hide","hide"),
          h4("YEAH !!")

      )

    }


  })




observe({
  if(input$save >0){
    isolate(previewAction$temp <- previewAction$temp+1)
  }
})

observe({
  if(input$hide >0){
    isolate(previewAction$temp <- previewAction$temp+1)
  }
})



}

shinyApp(ui, server)

非常感谢大家的帮助!

干杯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM