【发布时间】:2014-07-12 01:58:48
【问题描述】:
对不起,如果这是一个常见问题,但这让我发疯了。我需要向触发文件保存的 Shiny UI 添加一个 actionButton。实际的文件保存命令取决于 tabPanel 的哪个选项卡打开,我可以通过 tabPanel id 获取该信息。我遇到的问题是访问 actionButton 的状态并在之后重置它。
在 ui.r 中,我有这样的东西:
shinyUI(fluidPage(
titlePanel("myTitle"),
sidebarLayout(
sidebarPanel("",
actionButton("save", "Save File"),
# test to make sure the button is working
verbatimTextOutput("sb") # it increments when clicked
)
)
))
在 server.r 中,我正在尝试这样做:
shinyServer(function(input, output) {
# test to make sure the button is working
output$sb <- renderPrint({ input$save }) # increments when clicked
# here is the problem code:
if(input$save > 0) { # button was clicked, so...
input$save <- 0 # reset the flag
print("HERE") # and do something else
}
})
当然,我会检查 tabPanel 的状态,而不是打印“HERE”,如果我解决了这个问题,这可能会产生另一个问题。如何访问和更改 server.r 代码中 input$save 的值?没有证据表明 if() 条件语句中的代码正在执行,所以我假设逻辑测试要么没有被执行,要么返回 FALSE,即使每次单击按钮时 input$save 的值都会增加。
感谢您的任何建议。可能很明显,我对 Shiny 很陌生,到目前为止发现它相当不透明。
最好, ——迈克 C.
【问题讨论】: