【发布时间】:2013-12-11 19:28:56
【问题描述】:
我有一个包含两个不同操作的表单。第一个是上传文件,第二个是示例。当我单击其中一个按钮时,我的应用程序会执行某些操作,但服务器会保存单击的信息并且在我单击另一个按钮之前不会更改。
例如,如果我点击上传按钮而不选择文件,它什么也不做,但是如果我选择一个文件,服务器会上传文件并开始处理它而不点击上传按钮,因为服务器已经保存了过去的点击。我想知道是否可以重置每次点击的值。
索引.html
<form class="span12 menu-med-upload">
<div class="row-fluid">
<h3>Upload File .fasta</h3>
<div class="custom-input-file btn btn-inverse">
<input type="file" size="1" name="fileFasta" id="fileFasta" class="input-file" />
Select File
</div>
<img src="/static/img/check.png" class = "custom-input-check">
<div class="span12"></div>
<textarea class = "span12" rows = "10" style="resize: none;" id="textAreaFasta">
</textarea>
</div>
<button id="uploadFasta" type="button" class="btn btn-inverse action-button" >Upload File</button>
<button id="exampleFasta" type="button" class="btn btn-inverse action-button" >Example</button>
</form>
服务器.R
shinyServer(function(input, output, session) {
# Create a reactiveValues object, to let us use settable reactive values
values <- reactiveValues()
# To start out, lastAction == NULL, meaning nothing clicked yet
values$lastAction <- NULL
# An observe block for each button, to record that the action happened
observe({
if (input$exampleFasta != 0) {
values$lastAction <- 'example'
}
})
observe({
if (input$uploadFasta != 0) {
values$lastAction <- 'upload'
})
})
# Then you can use values$lastAction in reactive expressions, outputs, etc.
output$table <- renderText({
if (is.null(values$lastAction))
return(NULL)
if (identical(values$lastAction, 'upload'))
return(myRenderTable(matrixProtein(), "table", nameFile))
if (identical(values$lastAction, 'example'))
return(myRenderTable(matrixProteinExample(), "table", ""))
stop("Unexpected value for lastAction: ", values$lastAction)
})
})
注意:Joe Cheng 做了 server.R 的代码,我把这个例子的工作复制到shiny Change data input of buttons
【问题讨论】:
-
我不明白这个问题,有人可以编辑它更清楚吗?
标签: r shiny shiny-server