所以我正在尝试创建一个闪亮的应用程序,我有一个按钮,只显示文件已上传; 为此我使用conditionalPanel.
ui.R:
require(shiny)
shinyUI(pageWithSidebar(
headerPanel("My App"),
sidebarPanel(
fileInput("files", "Choose file"),
conditionalPanel(
condition = "input.files",
actionButton("submitFiles", "Submit files for processing"))),
mainPanel(h3("Nothing to see here"))
))
Run Code Online (Sandbox Code Playgroud)
我不认为我的服务器中有任何需要关心的内容.因为上面的例子没有做任何事情.在上述条件下,按钮从不显示,即条件永远不会出现.
我为我的条件尝试过的一些事情是input.files.length > 0
,在我上传文件之前input.files.size() > 0
,这两个因素都会导致按钮出现.我猜这是因为在选择文件之前输入$ files是一个空的data.frame,因此长度/大小非零,是吗?
在完成上传至少一个文件之前,我可以使用什么条件隐藏按钮?
我认为,另一种选择是,以取代conditionalPanel
用uiOutput
,并呼吁renderUI({actionButton(...)})
在server.R的观察/分离块,是看input.files(内if (nrow(input$files) < 1) return()
); 这是唯一的方法吗?如果我能以这种方式做到这一点,是什么让我选择其中一个(除了conditionalPanel
导致更少的代码)?
Sté*_*ent 42
您必须使响应输出返回上载状态并将suspendWhenHidden
此输出的选项设置为FALSE
.
更确切地说,在server.R中你肯定有一个反应函数,比如getData()
从上传的文件中创建一个数据帧.然后这样做:
getData <- reactive({
if(is.null(input$files)) return(NULL)
......
})
output$fileUploaded <- reactive({
return(!is.null(getData()))
})
outputOptions(output, 'fileUploaded', suspendWhenHidden=FALSE)
Run Code Online (Sandbox Code Playgroud)
在ui.R中,您可以conditionalPanel()
通过以下方式使用:
conditionalPanel("output.fileUploaded",
......
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6321 次 |
最近记录: |