-
-
Notifications
You must be signed in to change notification settings - Fork 31
Implement support for clientside callbacks in Dash for R #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
b34f3f7
79b0016
509af82
b85c6b7
e4fffaf
16ddb98
af6b56c
0c65b78
1c45fe9
c3eae14
b228846
73ef721
a1edd09
607f519
28ca2e7
c54ea0e
312b125
cb8fc1b
19e0785
4d1768b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from selenium.webdriver.support.select import Select | ||
import time | ||
|
||
app = """ | ||
library(dash) | ||
library(dashCoreComponents) | ||
library(dashHtmlComponents) | ||
|
||
app <- Dash$new() | ||
|
||
app$layout(htmlDiv(list( | ||
dccInput(id='input'), | ||
htmlDiv(id='output-clientside'), | ||
htmlDiv(id='output-serverside') | ||
) | ||
) | ||
) | ||
|
||
app$callback( | ||
output(id = "output-serverside", property = "children"), | ||
params = list( | ||
input(id = "input", property = "value") | ||
), | ||
function(value) { | ||
sprintf("Server says %s", value) | ||
} | ||
) | ||
|
||
app$clientside_callback( | ||
output('output-clientside', 'children'), | ||
params=list(input('input', 'value')), | ||
clientsideFunction( | ||
namespace = 'clientside', | ||
function_name = 'display' | ||
) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we allow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered about that as I was working on this PR; using the same syntax for both seems perfectly fine to me. I'll go ahead and make this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in e4fffaf |
||
|
||
app$run_server() | ||
""" | ||
|
||
|
||
def test_rscc001_clientside(dashr): | ||
dashr.start_server(app) | ||
dashr.wait_for_text_to_equal( | ||
'#output-clientside', | ||
'' | ||
) | ||
dashr.wait_for_text_to_equal( | ||
"#output-serverside", | ||
"Server says NULL" | ||
) | ||
input1 = dashr.find_element("#input") | ||
dashr.clear_input(input1) | ||
input1.send_keys("Clientside") | ||
dashr.wait_for_text_to_equal( | ||
'#output-clientside', | ||
'Client says "Clientside"' | ||
) | ||
dashr.wait_for_text_to_equal( | ||
"#output-serverside", | ||
"Server says Clientside" | ||
) | ||
dashr.clear_input(input1) | ||
input1.send_keys("Callbacks") | ||
dashr.wait_for_text_to_equal( | ||
'#output-clientside', | ||
'Client says "Callbacks"' | ||
) | ||
dashr.wait_for_text_to_equal( | ||
"#output-serverside", | ||
"Server says Callbacks" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from selenium.webdriver.support.select import Select | ||
import time, os | ||
alexcjohnson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
app = """ | ||
library(dash) | ||
library(dashCoreComponents) | ||
library(dashHtmlComponents) | ||
|
||
app <- Dash$new() | ||
|
||
app$layout(htmlDiv(list( | ||
dccInput(id='input'), | ||
htmlDiv(id='output-clientside'), | ||
htmlDiv(id='output-serverside') | ||
) | ||
) | ||
) | ||
|
||
app$callback( | ||
output(id = "output-serverside", property = "children"), | ||
params = list( | ||
input(id = "input", property = "value") | ||
), | ||
function(value) { | ||
sprintf("Server says %s", value) | ||
} | ||
) | ||
|
||
app$clientside_callback( | ||
output('output-clientside', 'children'), | ||
params=list(input('input', 'value')), | ||
clientsideFunction( | ||
namespace = 'clientside', | ||
function_name = 'display' | ||
) | ||
) | ||
|
||
app$run_server() | ||
""" | ||
|
||
|
||
def test_rscc001_clientside(dashr): | ||
os.path.join(os.path.dirname(__file__), "assets") | ||
dashr.start_server(app) | ||
dashr.wait_for_text_to_equal( | ||
'#output-clientside', | ||
'Client says "undefined"' | ||
) | ||
dashr.wait_for_text_to_equal( | ||
"#output-serverside", | ||
"Server says NULL" | ||
) | ||
input1 = dashr.find_element("#input") | ||
dashr.clear_input(input1) | ||
input1.send_keys("Clientside") | ||
dashr.wait_for_text_to_equal( | ||
'#output-clientside', | ||
'Client says "Clientside"' | ||
) | ||
dashr.wait_for_text_to_equal( | ||
"#output-serverside", | ||
"Server says Clientside" | ||
) | ||
dashr.clear_input(input1) | ||
input1.send_keys("Callbacks") | ||
dashr.wait_for_text_to_equal( | ||
'#output-clientside', | ||
'Client says "Callbacks"' | ||
) | ||
dashr.wait_for_text_to_equal( | ||
"#output-serverside", | ||
"Server says Callbacks" | ||
) |
Uh oh!
There was an error while loading. Please reload this page.