I am pretty new to Plotly Dash and have been struggling especially with multivalue dropdown callback and would really appreciate any help. Basically I've followed a tutorial and created a pie-chart if a single pillar(from my data) value is selected. I would like to achieve two things:
The default or initial chart should show all pillar and the number of projects
Multi selection of pillar values
My main issue is actually the creating the callback for these. Thank you in advance for any help!!
Here is my code
app = dash.Dash(__name__)
all = df.Pillar.unique()
app.layout=html.Div([
html.H1("PM dashboard"),
dcc.Dropdown(id='pillar-choice',
options=[{'label':x, 'value':x}
for x in all],
value='Service Provider',
multi=False),
dcc.Graph(id='my-graph',
figure={}),
])
#app.callback(
Output(component_id='my-graph', component_property='figure'),
Input(component_id='pillar-choice', component_property='value')
)
def interactive_graphs(value_pillar):
print(value_pillar)
dff = df[df.Pillar==value_pillar]
fig = px.pie(data_frame=dff, names='Pillar', values='Project No')
return fig
if __name__=='__main__':
app.run_server()
I think the problem here is that value_pillar will be a list, so you need to do something like:
dff = df[df.Pillar.isin(value_pillar)]
And if you want to show everything by default, you'll need to check the value of that argument for your default value and, if it matches the default, avoid filtering.
Answer in
How to replace remapColums with remapColumnsByName in free jqgrid
contains code to save and restore jqgrid column order.
It contains method to restore columns state:
var restoreColumnState = function (colModel) {
var colItem, i, l = colModel.length, colStates, cmName,
columnsState = getObjectFromLocalStorage(myColumnStateName);
if (columnsState) {
colStates = columnsState.colStates;
for (i = 0; i < l; i++) {
colItem = colModel[i];
cmName = colItem.name;
if (cmName !== "rn" && cmName !== "cb" && cmName !== "subgrid") {
colModel[i] = $.extend(true, {}, colModel[i], colStates[cmName]);
}
}
}
return columnsState;
};
This method causes invalid data posting from inline edit if new column is defined in server side.
jqgrid is populated from remote json data array. In this array columns must be the same as in column state.
If columns state is saved and new column is added to jqgrid in server code,
colStates[cmName] value is undefined.
This code causes new column to be added to end of jqgrid columns. However, in json data array it appears in the column as defined in server.
On inline edit, if row is saved, wrong values are assigned to form fields and invalid values are passed to server.
I tried to fix it adding colStates[cmName] !== undefined check:
if (cmName !== "rn" && cmName !== "cb" && cmName !== "subgrid" && colStates[cmName] !== undefined) {
but problem persists.
How to fix this that if new column is added to jqgrid colmodel in server, restoring column state allows to save correct data?
New column which is not found in saved columns list should appear in the same relative position as it is defined in colmodel. Column order shoudl corrspond to remote data from server.
Update
ColModel is defined in Razor view in variable cm
<script>
var
$grid,
myColumnsState,
isColState,
myColumnStateName;
$(function () {
var cm= #Html.Raw(Model.GetColModel());
$grid = $("#grid");
myColumnStateName = #Model.ColumnStateName();
myColumnsState = restoreColumnState(cm, myColumnStateName);
isColState = typeof (myColumnsState) !== 'undefined' && myColumnsState !== null;
$grid.jqGrid({
page: isColState ? myColumnsState.page : 1,
sortname: isColState ? myColumnsState.sortname : "",
sortorder: isColState ? myColumnsState.sortorder : "",
....
</script>
I know the problem very good! One need to implement some kind of validating checks of the previously saved state of the grid before the usage. The deepness of checks could depend on the exact requirements of your application and from the information which one knows exactly. The most opened and unclear thing: should one make some correction/fixing of the previously saved state or should one discard the state on the first small error? The answer on the question depends on the project where jqGrid are used. Deep fixing could include fixing of sorting parameter and modifying previously saved filter. Another example: the state could include ids of selected rows, but the fixing of the part of the state could be bad idea in the common case. One loading of the data could imply one setting of selected rows, but loading of another data (unfiltered for example) could do have the rows and the rows should be do selected. There are no best choice in the case, all depends on the exact project requirements. In any way the implementation of the state validation/fixing isn't a simple code.
Only because of the complexity of the problems of validation of previously saved state and the existence of different scenarios of validation I didn't implemented such feature in free jqGrid. Any good implementation needs time and the resulting code will be not simple. It will have some options for some typical scenarios. I would like to implement the feature in the future, but I just didn't found the time for the implementation, because I have to do my main job to earn money for my family and I still try to help other people in the community who have small, but important, for the person, problems with jqGrid of free jqGrid.
I want to create a view in cb that will show some data based on date-range input.
My question is how can I distinct field from the data?
Here is my map code:
function (doc, meta) {
if(!doc.clipGeneration.fromCache){
var eiid = doc.clipGeneration.batchId;
if (eiid == null){
eiid = "API";
}
if ( !(doc.clipGeneration.externalId.indexOf("API_INTERVAL_TEST")>=0) ) {
emit([doc.clipGeneration.clipStyle, eiid,doc.eventOccurenceTimeStamp[0], doc.eventOccurenceTimeStamp[1], doc.eventOccurenceTimeStamp[2],doc.eventOccurenceTimeStamp[3]], doc.insertRawTimestamp);
emit([doc.clipGeneration.clipStyle, "ALL",doc.eventOccurenceTimeStamp[0], doc.eventOccurenceTimeStamp[1], doc.eventOccurenceTimeStamp[2],doc.eventOccurenceTimeStamp[3]], doc.insertRawTimestamp);
emit([doc.eventOccurenceTimeStamp[0], doc.eventOccurenceTimeStamp[1], doc.eventOccurenceTimeStamp[2],doc.clipGeneration.clipStyle], doc.insertRawTimestamp);
}
}
}
The reduce is _count, and the filters for example are:
startkey: [2015,1,1,null]
endkey: [2015,1,31,"\uffff"]
The output is as expected by the date-range:
{"key":[2015,1,11,"5001188"],"value":1},
{"key":[2015,1,12,"100022"],"value":5},
{"key":[2015,1,12,"155"],"value":11},
{"key":[2015,1,13,"100022"],"value":9},
{"key":[2015,1,13,"155"],"value":6},
{"key":[2015,1,13,"5001159"],"value":1},
{"key":[2015,1,13,"5001190"],"value":3},
{"key":[2015,1,14,"100022"],"value":12},
{"key":[2015,1,14,"5001194"],"value":1},
{"key":[2015,1,15,"100022"],"value":11},
{"key":[2015,1,16,"100022"],"value":10},
{"key":[2015,1,18,"100022"],"value":8},
{"key":[2015,1,18,"5001096"],"value":6},
{"key":[2015,1,18,"5001194"],"value":3}
But as you can see "100022" repeat many times, how can I make somthing like distinct in sql, so it will be shown only once?
Thanks
There is no way to actually make ONLY the ID field distrinct. You can reduce by key, but only the whole key - so [date, id] in your case. You can do this in N1QL, because it has an actual DISTINCT keyword just like SQL, but that's still in developer preview at the moment.
I am using primefaces p:barChart which is a part of the jqplot api.
I want to remove the column number (the lest number 1 ) from the jqplot-highlighter-tooltip()
I assume the answer is in one of the options in the following
http://www.jqplot.com/docs/files/jqPlotOptions-txt.html but I didn't find the correct one
Can someone can please point me to the relevant attr ?
Thanks
function ext() {
this.cfg.highlighter = {
tooltipAxes: 'y'
};
}
I'm new to sqlalchemy and could use some help.
I'm trying to write a small application for which i have to dynamically change a select-statement. So I do s = select([files]), and then i add filters by s = s.where(files.c.createtime.between(val1, val2)).
This works great, but only with an AND-conjunction.
So, when I want to have all entries with createtime (between 1.1.2009 and 1.2.2009) OR createtime == 5.2.2009, I got the problem that i don't know how to achieve this with different filter-calls. Because of the programs logic it's not possible to use s= s.where(_or(files.c.createtime.between(val1, val2), files.c.createtime == DateTime('2009-02-01')))
Thanks in advance,
Christof
You can build or clauses dynamically from lists:
clauses = []
if cond1:
clauses.append(files.c.createtime.between(val1, val2))
if cond2:
clauses.append(files.c.createtime == DateTime('2009-02-01'))
if clauses:
s = s.where(or_(*clauses))
If you're willing to "cheat" by making use of the undocumented _whereclause attribute on Select objects, you can incrementally specify a series of OR terms by building a new query each time based on the previous query's where clause:
s = select([files]).where(literal(False)) # Start with an empty query.
s = select(s.froms).where(or_(s._whereclause,
files.c.createtime.between(val1, val2)))
s = select(s.froms).where(or_(s._whereclause,
files.c.createtime == datetime(2009, 2, 1)))
Building up a union is another option. This is a bit clunkier, but doesn't rely on undocumented attributes:
s = select([files]).where(literal(False)) # Start with an empty query.
s = s.select().union(
select([files]).where(files.c.createtime.between(val1, val2)))
s = s.select().union(
select([files]).where(files.c.createtime == datetime(2009, 2, 1)))