Button submit R with shiny

2019-06-22 08:25发布

问题:

I'm trying to implement a form to upload a file, but start to do operation when I click on a submit button, the problem is that a have a strange mistake and I don't know what's it, I made the example of the tutorial and it worked without problem, now I'm implementing the same but with index.html and it don't work.

The mistake is: "Error in if (input$uploadFasta == 0) return(NULL) : argument is of length zero"

my index.html is like:

<form class="span12 menu-med-upload">
    <div class="row-fluid">
        <center>
          <div class="custom-input-file btn btn-inverse">
            <input type="file" size="1" id="fileFasta" class="input-file" />
          </div>
        </center>
        <button id="uploadFasta" type="button" class="btn action-button shiny-bound-input" >go!</button>
    </div>
</form>

my server.R is like:

output$table <- renderText({
    if(input$uploadFasta == 0)
        return(NULL)
    myRenderTable()
})

somebody know what's the problem, and thank for all and sorry if this topic was open before but I could not find.

回答1:

Action button is a custom input binding and I'll bet it's not being loaded.

Add a global.R file in the same directory as server.R, and have it contain this:

addResourcePath(
    prefix='actionbutton', 
    directoryPath=system.file('actionbutton', 
                          package='shinyIncubator'))

Then in your index.html, add the following to <head>:

<script src="actionbutton/actionbutton.js"></script>

(As always, be sure to have an explicit closing </script> tag--don't use <script />.)