【发布时间】:2016-01-28 12:12:21
【问题描述】:
今天我正在尝试创建一个 renderUI,其表单和内容取决于 reactiveValues 的值。我正在做一个闪亮的仪表板
在初始状态下,用户会点击按钮,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还在重新初始化???
你有解决这个问题的想法吗?
非常感谢您!
干杯
恰
【问题讨论】:
-
所以看起来这里的问题是你创建动作按钮的反应实际上是检查 input$button 的状态,所以每次状态改变时,整个事情都会再次运行。尝试使用 input$button 隔离这些部分
-
基本上,如果您在其他地方打印它的状态,是否将其隔离在一个地方并不重要。