Is there a way in dash to pass the result of a function to a dcc.input value? - plotly-dash

I need to pass the variable 'y' to the input dcc.Input(id='n', type='number', value=y, min=0.25, max=4)
The only thing working was using a constant value for the default value input
dcc.Input(id='n', type='number', value=1.0, min=0.25, max=4)

Related

Increment index without show its value on xtend

I'm trying to generate some code with a xtend function , that function uses foor loop that with variable that its increemented , the problem is that that the value of the variable is shown on the generated file, how I can avoid it?
def codeGenerate(users u) '''
«var index = 0»
«FOR user :u»
«index +=1» //The problem is here the value of index is printed, how I can incremet the value without printing it?
«ENDFOR»
'''
It's not nice but this should do the trick:
«{index +=1; null}»

How to display number values with commas in form

In my Access query, I have the query using a VBA function to figure the value that goes in the query field.
In the form, if the stringval textbox has a value, then I want to compute it, but if not, it should remain empty (null).
Function GetValue(stringval, numval)
Dim result
stringval= stringval & ""
result= IIf(stringval<> "", numval* 1.5, Null)
GetValue = Int(result)
End Function
Now, I have a form that uses this query, and on the form is a textbox that displays the query value. I want the value to be formatted with commas in the numbers for easy reading. Everything I've tried so far does not show any commas.
I've tried:
used Standard for the Format > Formatfor the textbox (in properties)
putting #,###.### in the textbox Format value
putting #,##0.0## in the textbox Format value
changing Data > Text Format but it only gives me Plain Text and Rich Text - no option for numbers.
returning a double from the function
Note: if I don't use a custom VBA function, and write the formula directly into the query, then it does display commas. But when I move the formula into the function then the commas are lost.
What do I do?
[update]
I tried Gustav's solutions and since they didn't work for me, I added those as items to my "what I've tried" list above.
Also, if I look at the query in datasheet view, the number values sort alphabetically instead of by the size of the value. When I used the forumulae directly in the query instead of using functions, it sorted by the value of the number. I hope this is a clue.
Numbers carries no format. A format is applied when displayed only.
But be sure to return a Double if not Null:
Function GetValue(stringval, numval)
Dim result
If stringval & "" <> "" Then
result = Int(CDbl(numval) * 1.5)
Else
result = Null
End If
GetValue = result
End Function
Then apply your Format to the textbox
#,##0.0##
Or force a formatted string to be returned:
If stringval & "" <> "" Then
result = Format(Int(CDbl(numval) * 1.5), "#,##0.0##")
Else
result = Null
End If
and skip formatting of the textbox.
The solution is this: the function has to be declared as a double.
That allows the query's datasheet view to know it is displaying numbers - and so you can set the field's format to Standard for the comma to display. This also allows the form to know it has a number and it will display the comma there, too. I knew it had to do with double, but didn't realize before that the function needed to be declared as such.
Function GetValue(stringval, numval) as double '<----THIS!!!!
Dim result
If stringval & "" <> "" Then
result = numval * 1.5
Else
result = 0 `<--can't return null here; use nz function in control source for textbox
End If
GetValue = int(result) 'to remove decimals
End Function
The problem I was having was in some of my functions I need to return double or null, because I wanted textboxes to remain blank if they contained no data. Now, at least I know how to make the numbers generated by functions to display commas.
And here is how to deal with the fact that you can't return null as the value of a double. The function is originally from here.
Put this function in a module so it is public, and then in the control source for the textbox, instead of just putting the field value, put Zn(fieldvalue). This works like a charm (although using functions in the control source seems to have a delay on the form display). This way you can keep the underlying value as a double and still get commas to display in both the form and the query whilst keeping the field blank if necessary.
Public Function Zn(pvar)
' Return null if input is zero or ""
If IsNull(pvar) Then
Zn = Null
ElseIf IsNumeric(pvar) Then
If pvar = 0 Then
Zn = Null
Else
Zn = pvar
End If
Else
If Len(pvar) = 0 Then
Zn = Null
Else
Zn = pvar
End If
End If
End Function

passing parameters in ado.net source

I wanted to pass a parameterized query in ado.net source and i rea don this post that only way to do this is to use expressions.
So here is my expression
"SELECT
LEDGER_YR_MO,
LOCATION,
FDR_FND_NO,
FDR_INVST_POOL_CD,
FISCAL_YR_BEG,
FISCAL_YR_END,
POST_DATE,
FDR_FND_TTL,
FDR_FND_TYPE_CD,
FDR_FND_PURP_CD,
FDR_CR_ELIG_FL,
FDR_ANN_CR_RATE,
FDR_MTH_CR_RATE,
FDR_CR_AMT,
FDR_TR_ELIG_FL,
FDR_ANN_TR_RATE,
FDR_MTH_TR_RATE,
FDR_60MTH_AVG_SHARE_PRC,
FDR_TR_AMT,
FDR_PROJ_GEP_INCM_AMT,
FDR_TR_AUGMENTATION_AMT,
FDR_GEP_NET_PAYOUT_AMT
FROM
FS0TST.UCOP_FDR_TR_CR where
LEDGER_YR_MO = '"+ (DT_WSTR,30) #[User::END_LEDGER_YR] +"' "
but when I click evaluate the expression , I see blank instead of variable ..does anyone know the possible issue:
Here is the evaluate expression looks like
SELECT
LEDGER_YR_MO,
LOCATION,
FDR_FND_NO,
FDR_INVST_POOL_CD,
FISCAL_YR_BEG,
FISCAL_YR_END,
POST_DATE,
FDR_FND_TTL,
FDR_FND_TYPE_CD,
FDR_FND_PURP_CD,
FDR_CR_ELIG_FL,
FDR_ANN_CR_RATE,
FDR_MTH_CR_RATE,
FDR_CR_AMT,
FDR_TR_ELIG_FL,
FDR_ANN_TR_RATE,
FDR_MTH_TR_RATE,
FDR_60MTH_AVG_SHARE_PRC,
FDR_TR_AMT,
FDR_PROJ_GEP_INCM_AMT,
FDR_TR_AUGMENTATION_AMT,
FDR_GEP_NET_PAYOUT_AMT
FROM
FS0TST.UCOP_FDR_TR_CR where
LEDGER_YR_MO = ''
When you click the Evaluate Expression button, no code actually gets executed, so the only thing SSIS can look at is the static default value you gave your variable.
If you want to see a value instead of a blank in the Evaluate Expression, you have to give your variable a default value, even if you don't intend to use that value. When the SSIS package is executed, whatever code you use to populate the variable will overwrite the default value, so having a default value is harmless.

How to call a function with less arguments that is set (Python 3)

I am making a terminal emulator in Python 3. The commands are being stored in functions, like:
def rd(os_vartmp, os_vartmp2):
if os_vartmp == None:
print('rd [path] [-S]')
print('Delete a folder')
else:
if os.path.isfile(os_vartmp) == True:
if os_vartmp2 == '-S': print('a')
else:
print(ERR5)
a = input('Command: ')
The terminal works like this:
Asks user for input
Splits the input
Uses the first part of input to search a function in locals
If there is one, uses the rest part of input as argument
Calls the function
The thing here is, when i call the function 'rd' with, for example, 'rd "boot.py" -S' it works just fine. But if i need to call it like this: rd "boot.py", it throws me a error about 1 argument given when 2 are required. Is there a fix for that?
You can make an argument optional by assigning a value in the method definition. For example:
def Add(x=0, y=0):
return x+y
If you input only one value, y will default to 0. If I wanted to give y a value but have x fall back on it's default value I could do Add(y=10). I hope this helped!
Have you tried this?
def rd(os_vartmp, os_vartmp2="-S"):
Instead of trying to get null value, which would require rd("boot.py",null), you can ser default value and then you can do rd("boot.py").
Hope it works.

Null value passed as string "null" from listBox with no selection

I am checking that a user makes a selection from a listbox. It appears that if no selection is made, the value passed to the server handler is "null" NOT null. Is this working as intended?
This code correctly tests for no selection in selectList listBox.
Logger.log("e.parameter.selectList"+e.parameter.selectList)
if (e.parameter.selectList === "null") {
error = true;
errortext = "no valid region selected";
Logger.log('error')
}
I expected
if (!e.parameter.selectList )... to work
Yes, this is known.
All the values in the handler are returned as string (except the dateBox value, I am not sure though). E.g checkbox value is returned "true"/"false" not true/false (a boolean value). You will have to parse these strings first to get the values in the desired form.
I usually use Utilities.jsonParse(stringValue)