今天我正在尝试使用一个renderUI,其形式和内容取决于reactiveValues的值。我正在研究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仍然重新初始化???
你有想法解决这个问题吗?
非常感谢你!
干杯
茶
答案 0 :(得分:0)
以下是代码:
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)
非常感谢大家的帮助!!
干杯