Last active
October 21, 2015 23:38
-
-
Save davidarndt/0c2a98a0236f1257fd45 to your computer and use it in GitHub Desktop.
Shiny fileInput reset using JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shiny fileInput reset using JavaScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
/* clear file button control */ | |
var fileControl = $("#file1"); | |
$("#clearFile1").on("click", function () { | |
fileControl.replaceWith( fileControl = fileControl.clone( true ) ); | |
$("#file1_progress").hide(); | |
}); | |
$("#uploadFormat").on("change", function () { | |
fileControl.replaceWith( fileControl = fileControl.clone( true ) ); | |
$("#file1_progress").hide(); | |
}); | |
/* file input progress bar control */ | |
$( "#file1" ).change(function() { | |
document.getElementById("file1_progress").setAttribute('style', "height:20px; margin-top:5px;"); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shinyServer(function(input, output, session) { | |
values <- reactiveValues( | |
file1 = NULL | |
) | |
observe({ | |
input$clearFile1 | |
input$uploadFormat | |
values$file1 <- NULL | |
}) | |
observe({ | |
values$file1 <- input$file1 | |
}) | |
output$summary <- renderText({ | |
return(paste("Uploaded file: ", values$file1$name)) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shinyUI(bootstrapPage( | |
tags$head( | |
tags$style(".clearButton {float:right; font-size:12px;}") | |
), | |
headerPanel("Reset file input example"), | |
sidebarPanel( | |
HTML("<button id='clearFile1' class='action-button clearButton'>Clear</button>"), | |
fileInput('file1', NULL, width="80%"), | |
selectInput('uploadFormat', label = "Select upload format", | |
choices = c( | |
"Option 1" = 'f1', | |
"Option 2" = 'f2', | |
"Option 3" = 'f3'), | |
selected = 'f1') | |
), | |
mainPanel( | |
h4("Summary"), | |
verbatimTextOutput("summary") | |
), | |
singleton(includeScript("active.js")) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Stack Overflow: http://stackoverflow.com/questions/17352086/how-can-i-update-a-shiny-fileinput-object/33271056#33271056