Dash, circular callback inputs - callback

I have a problem with an application I want to code with Dash. I have two different checklists (indicator A, indicator B). My goal is that the user can choose multiple options for only one indicator. So it is allowed to choose a,b,c and 1. It should also be possible to select c and 2,3 at the same time. The selection of a,c and 1,2 on the other hand, should be prevented. My approach to this is the following code:
app.layout = html.Div([
html.Label('indicator A'),
dcc.Checklist(
id = 'i_a',
options=[
{'label': 'a', 'value': 'a'},
{'label': 'b', 'value': 'b'},
{'label': 'c', 'value': 'c'}
],
value = ['a']
),
html.Label('indicator B'),
dcc.Checklist(
id='i_b',
options=[
{'label': '1', 'value': '1'},
{'label': '2', 'value': '2'},
{'label': '3', 'value': '3'}
],
value=['1']
),
])
#app.callback(
Output('i_b', 'value'),
Input('i_a', 'value')
)
def change_b(value_a):
return ['1']
#app.callback(
Output('i_a', 'value'),
Input('i_b', 'value')
)
def change_b(value_b):
return ['a']
This creates an endless loop because the callbacks trigger each other. However, I have no idea how to solve the problem. I am grateful for any help :)

I think what you need is the new circular callbacks ability. Check out the examples on this page, which I think are very similar to what you're doing.

Related

Unable to save address after data migration

One or more input exceptions have occurred.
"postcode" is required. Enter and try again.
"countryId" is required. Enter and try again.
I'm filling these values in my account edit address page, but facing this issue.
https://prnt.sc/u95nez
During migration, there is a problem with the loss postcode and telephone attributes values from customer_form_attribute and eav_form_element tables.
Adding missing values might help:
INSERT INTO customer_form_attribute (form_code, attribute_id)
VALUES ('adminhtml_customer_address', '33'),
('customer_address_edit', '33'),
('customer_register_address', '33'),
('adminhtml_customer_address', '34'),
('customer_address_edit', '34'),
('customer_register_address', '34');
INSERT INTO eav_form_element (element_id, type_id, fieldset_id, attribute_id, sort_order)
VALUES (NULL, '1', NULL, '33', '7'),
(NULL, '2', NULL, '33', '7'),
(NULL, '3', NULL, '33', '6'),
(NULL, '4', NULL, '33', '6'),
(NULL, '1', NULL, '34', '9'),
(NULL, '2', NULL, '34', '9'),
(NULL, '3', NULL, '34', '8'),
(NULL, '4', NULL, '34', '8');

MapPartitions does not execute print

I've a problem that I'm hoping someone can explain it to me.
Let's assume my data looks like this:
('1', ['1', '1', '-1']),
('1', ['1', '2', '-2']),
('1', ['1', '3', '-3']),
('1', ['1', '4', '-4']),
('1', ['1', '5', '-5']),
('1', ['1', '6', '-6']),
('2', ['2', '7', '-7']),
('2', ['2', '8', '-8']),
('2', ['2', '9', '-9'])
and I store it in an RDD with two partitions. One partition contains data for key = '1' and the other contains data for key = '2'. Now, when I run:
def do_something(partition):
print('hello')
for element in partition:
if element[0] != '1':
yield element
my_rdd_new = my_rdd.mapPartitions(do_something)
It doesn't print 'hello' but my_rdd_new contains the right subset of data, i.e.:
('2', ['2', '7', '-7']),
('2', ['2', '8', '-8']),
('2', ['2', '9', '-9'])
Can anyone explain why this is happening?!
If it helps, I'm using spark 2.0.1 and running the code in Jupyter IPython notebook.
Update: It seems Jupyter IPython is the problem. I ran it in the command prompt and it works. Now, the question is: Why does it happen and how it can be fixed?!
Thanks

Why matlab skips 2nd half of labels?

Here is a pretty streightforward code for displaying matrix in scaled color using imagesc command. The problem is that final figure has wrong labeling and doesnt show 2nd half of labels(it should be from 1 to 21, but it is from 1 to 10)
figure;
imagesc(magic(21));
set(gca,'XTickLabel',{'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21'})
set(gca,'YTickLabel',{'1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' '20' '21'})
I am using Ubuntu 16.04 and Matlab 2016b.
You set up the label text, but not the location, thus it will automatically put label locations and then substitute their text.
To set up the locations of the labels, first do:
set(gca,'XTick',...)
Then you can write in those labels whatever you preffer:
set(gca,'XTickLabel',{'banana', 'platano', 'potato',... })
You have to assign locations for those ticks, not just add labels.
figure;
imagesc(magic(21));
ax1 = gca;
ax1.YTick = 1:21;
ax1.XTick = 1:21;
ax1.XTickLabels = {'One','Two','Three',...
ax1.YTickLabels = {'Red','Brown','Green',...
Also since Matlab 2014b Mathworks created a new graphics system. You can access your graphics as objects directly instead of using set and get everywhere.
You can test this:
imagesc(magic(21));
set(gca,'XLim',[1 21])
set(gca,'XTick',[1:1:21])
set(gca,'XTickLabel',{'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21'})
set(gca,'YLim',[1 21])
set(gca,'YTick',[1:1:21])
set(gca,'YTickLabel',{'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21'})

sugarcrm 6.5 set number columns to 3 in one tab/panel, 2 in other tabs

I know how to set the columns in a detailview to 3 columns instead of the default 2 by putting into detailviewdefs.php
(in modules/EvMgr_Pgm/metadata if creating a custom module
or in custom/modules/EvMgr_Pgm/metadata if editing an existing module)
'maxColumns' => '3',
'widths' =>
array (
0 =>
array (
'label' => '8',
'field' => '19',
),
1 =>
array (
'label' => '8',
'field' => '19',
),
2 =>
array (
'label' => '8',
'field' => '19',
),
),
However, that sets the columns for ALL the tabs/panels in a detailview
Is there a way I can have there be 3 columns in one tab/panel and 2 columns (default) in the other tabs/panels?
If you change the widths to exceed 100 it'll recalculate the widths for a panel/table that has 3 or more columns. Try this:
'maxColumns' => '3',
'widths' =>
array (
0 =>
array (
'label' => '10',
'field' => '30',
),
1 =>
array (
'label' => '10',
'field' => '30',
),
2 =>
array (
'label' => '10',
'field' => '30',
),
),
This uses the standard 2 column 10/30 width. When a panel is created with 3 columns it'll recalculate the widths since it is greater than 100. At least as of 6.5.18 it does. Most likely it does for previous versions as well.

Perl DBI Oracle not preserving column order after SELECT

I'm using Perl v5.12.3 built by ActiveState on Windows. DBD::Oracle version 1.27. DBI version 1.616. I'm selecting the data below in this particular order and wanting the resulting data to be retrieved in that same order. Below are the code samples and some examples.
SQL Snippet (contents of $report_sql below)
select student_number, lastfirst, counselor,
a.dateenrolled as "Date Enrolled 1", a.dateleft as "Date Left 1", a.termid as "Term ID 1", a.course_number as "Course Number 1",
a.expression as "Expression 1", b.dateenrolled as "Date Enrolled 2", b.dateleft as "Date Left 2",
b.termid as "Term ID 2", b.course_number as "Course Number 2", b.expression as "Expression 2"
Perl code snippet
## run the resulting query
my $report_result = $dbh->prepare( $report_sql );
$report_result->execute();
while( my $report_row = $report_result->fetchrow_hashref())
{
print Dumper(\$report_row); ## contents of this posted below
Contents of print Dumper for $report_row
$VAR1 = \{
'Expression 2' => 'x',
'LASTFIRST' => 'xx',
'Term ID 1' => 'xx',
'Date Enrolled 2' => 'xx',
'Course Number 1' => 'xx',
'Term ID 2' => 'xx',
'STUDENT_NUMBER' => 'xx',
'Date Left 2' => 'xx',
'Expression 1' => 'xx',
'COUNSELOR' => 'xx',
'Date Left 1' => 'xx',
'Course Number 2' => 'xx',
'Date Enrolled 1' => 'xx'
};
Order I EXPECTED it to be printed
$VAR1 = \{
'STUDENT_NUMBER' => 'xx',
'LASTFIRST' => 'xx',
'COUNSELOR' => 'xx',
'Date Enrolled 1' => 'xx',
'Date Left 1' => 'xx',
'Term ID 1' => 'xx',
'Course Number 1' => 'xx',
'Expression 1' => 'xx',
'Date Enrolled 2' => 'xx',
'Date Left 2' => 'xx',
'Term ID 2' => 'xx',
'Course Number 2' => 'xx',
'Expression 2' => 'x'
};
One thing to note is that this query being ran is one of many that are being ran. This particular script runs through a series of queries and generates reports based on the returned results. The queries are stored in files on the hd alongside the perl script. The queries are read in and then ran. It's not always the same columns being selected.
You used a hash. Hash elements have no controllable order*. The order of elememts in an arrays can be controlled. If you want to present the order in which the fields were received, use an array instead of hash.
If you actually need the names, you can get the ordered names of the fields using #{ $sth->{NAME} }. You should still use an array for efficiency reasons, but you could use a hash if you wanted to.
* — Just like array elements are returned in the order they are "physically" organised in the array, hash elements are returned in the order they are physically organised in the hash. You cannot control where an element is physically placed in a hash, and the position changes as the hash is changed. With an array, you decide the physical position of an element, and it will remain in that position.
When the order of columns in a DBI result matters you can get the column names and values as array references.
...
my $names = $report_result->{NAME}; # or NAME_lc or NAME_uc
while( my $report_row = $report_result->fetchrow_arrayref() ) {
for my $col_idx ( 0 .. $#{$names} ) {
print "$names->[$col_idx]: $report_row->[$col_idx]\n";
}
}
Back before I had to worry about internationalization I used this a lot to generate CSV reports, just pass the NAME array to Text::CSV before passing the result arrays and writing a report just becomes writing a query.