I'm using the Dash Upload component, which in turn uses react-dropzone.
I can drag a file into the component and the corresponding callback will fire.
I can then drag a different file into the component and the callback will fire again.
But, if I drag a file into the component (which fires the callback) and then drag the same file into the component again, the callback does not fire.
There's a demo app in this Gist that demonstrates the behavior.
Searching for similar problems (stack-overflow, github) suggests that this behavior is to be expected because from the browser's point of view nothing has changed. Both of those discussions seem to end up with solutions that involve setting the .value part of some element to '', so that the browser sees the second drop event as a change.
Chriddyp contributed links to the relevant bit of code in Dash and pointed me to the react-dropzone component.
Is there a way to make dropping the file twice in a row work in Dash using react-dropzone?
Thanks!
g.
In Dash, callbacks are invoked every time a property changes. If you upload the same file a second time, the properties (e.g. the file name) are unchanged, and the callback will thus not be invoked. This is expected behavior.
To ensure that a callback is invoked every time, you must ensure that the Input property actually changes. One option would be to add a new property to the Upload component similar to the n_clicks property of buttons, say n_uploads, which is incremented each time a file is uploaded.
The easiest solution for the problem at hand would probably be to use the custom dash uploader instead. Among other things, it supports uploading the same file multiple times.
A bit late answer. I found a solution which is just reset the contents and filename to None in the Output of the callback.
A simple example
import dash
from dash import dcc, html
from dash.dependencies import Input, Output, State
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Upload(html.Button('Upload File', id='btn_id'), id='upload_id'),
html.P(id='show_id'),
])
#app.callback(
Output('show_id', 'children'),
Output('upload_id', 'contents'),
Output('upload_id', 'filename'),
Input('upload_id', 'contents'),
State('upload_id', 'filename'),
State('btn_id', 'n_clicks'),
)
def uploaded_a_file(contents, filename, n_clicks):
if not contents:
raise dash.exceptions.PreventUpdate
msg = f'Uploaded {filename} for {n_clicks} time.'
return msg, None, None
if __name__ == '__main__':
app.run_server(debug=True)
Another workaround, similar to #aura's, is to replace the upload component entirely with a callback. This strategy can be useful when replacing "contents" would lead to circular callbacks.
See https://github.com/plotly/dash-core-components/issues/816#issuecomment-1032635061
I am trying to access and click the 'X' button via selenium in python to be able to be redirected to the next page and load some information from it. However, I am having a hard time finding the element, do not know whether it is because of being inside a class or something else. Can you guys help me out to actually click on the button. Code below is what I currently have.
Thank you in advance:
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
import time
from selenium import webdriver
driver = webdriver.Firefox()
url = 'https://shop.axs.co.uk/Lw%2fYCwAAAAA6dpvSAAAAAABB%2fv%2f%2f%2fwD%2f%2f%2f%2f%2fBXRoZW8yAP%2f%2f%2f%2f%2f%2f%2f%2f%2f%2f'
opts = Options()
browser = Firefox(options=opts)
browser.get(url)
#wait for all elements to load
time.sleep(5)
#working lines are commented out
#search_form = browser.find_element_by_class_name("modal-open")
browser.find_element_by_class_name('btn-close-svg pull-right').click()
Remove this lines -
opts = Options()
browser = Firefox(options=opts)
use the xpath here-
driver.find_element_by_xpath(".//div[#class='btn-close-svg pull-right']").click()
I want to link as3 code to a webpage. I click a button and then go to a web page. I used navigateToUrl. When I compile my fla file then the button is working perfect, going to the required webpage. But without compiling the fla file, when I directly run my swf file, then I cannot go to the required webpage. Why does this happen? Here is my code.
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.navigateToURL;
import flash.net.URLRequest;
link3.addEventListener(MouseEvent.CLICK, WebHyperlink);
link3.buttonMode=true;
function WebHyperlink(e:MouseEvent)
{
var myURL:URLRequest = new URLRequest("http://www.republicofcode.com/");
navigateToURL(myURL, "_blank");
}
You have a security exception because Flash Player blocks internet access to your swf file. To see that exception, you can install a Flash Player debug version from here and to avoid the problem, take a look on my answer for this question.
Hope that can help.
I'm facing a logic error here when i want to close tab in firefox through ExternalInterface, strangely nothing goes wrong in my output and compiler ,
import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.external.ExternalInterface;
letsPlay.addEventListener(MouseEvent.MOUSE_DOWN, loadIntro);
function loadIntro(e:MouseEvent){
sndStart.play();
sndmChannel.stop();
//System.exit(0);
fscommand("quit");
ExternalInterface.call("window.open","http://localhost/GAME_FLASH/stage1/stage1story.html","_blank");
ExternalInterface.call("closeWindow");
}
Firefox won't close the tab and won't the desired html in new window, i've checked everything including my html page. All the "import flash.bla bla" is complete nothing goes wrong there.
I tried to copy a text to clipboard with As3, when I run it on Flash Player it works, but if I include it in a page and I upload it, it doesn' t work.
The code:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("sendTextFromJS", receiveTextFromJS);
function receiveTextFromJS(t:String):void {
System.setClipboard(t);
}
Flash receives the text from JavaScript, but it not insert it in the ClipBoard. Someone knows why?
I guess, Security. FP 10 later securiy changes.
read this article: http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes.html#head31
I recommend. implements using a Clipboard Class