두 가지 다른 동작이있는 양식이 있습니다. 첫 번째는 파일을 업로드하는 것이고 두 번째는 예제를위한 것입니다. 이 중 하나를 클릭하면 앱에서 어떤 작업을 수행하지만 서버는 클릭 정보를 저장하고 다른 버튼을 클릭 할 때까지 변경 사항을 저장하지 않습니다.함수 observe() 및 reactValues ()는 어떻게 작동합니까?
예를 들어 파일을 선택하지 않고 업로드 버튼을 클릭하면 아무 것도 실행되지 않지만 파일을 선택하면 서버는 파일을 업로드하고 서버가 저장 했으므로 업로드 버튼을 클릭하지 않고 파일을 처리하기 시작합니다. 과거의 클릭. 각 클릭에 대해 값을 재설정 할 수 있는지 알고 싶습니다.
Index.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>
Server.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)
})
})
주 : 조 쳉 server.R의 코드를 만들어, 나는 shiny Change data input of buttons
나는이 질문을 이해하지 못한다. 누군가가 그것을 더 명확하게 편집 할 수 있을까? –