Is there a way to use the result of last run in the current run in Shiny? - shiny-reactivity

I am using Shiny to build a dynamic dashboard for the user. I used if statement to divide my code into two main parts. There is an input called "New Line" that user needs to enter "Yes" or "No" as the value for this parameter. If user selects "Yes" the first part of the code will be ran and if he selects "No", it means that the first part is ran before and just the second part of the code needs to be ran. In the second part, there are some parameters from the first part. I want for Shiny to save the results and parameters calculate from ("New Line"==Yes) and use it for the next runs("New Line"==No) until the user change the answer for "New Line" to "Yes" again.
I used observeEvent function and an action button in Shiny. But the problem is that the results of ("New Line"==Yes) can not be used for the next runs.
shinyserver(function(input,output)){
observeEvent(input$click,{
if(input$'New Line' == 'Yes'){}
if(input$'New Line' == 'No'){}
})
}
I expect whenever user enters No for the New Line and hits the action button, the code can use the variables that are calculated when the New Line was Yes. But now whenever I set New Line as No and hit the action button , R just runs the second if. I can copy and paste all the lines from first if to tell R to run all of them again but those line takes about 30 minutes and I do not want to repeat them.

You need to serialise your values somewhere.
One example:
shinyserver(function(input,output)){
observeEvent(input$click,{
if(input$'New Line' == 'Yes'){
data <- result_of_some_function()
some_other_things()
write.csv(data, "file.csv") # saving the data somewhere on disk
}
if(input$'New Line' == 'No'){
mypreviousdata = read.csv("file.csv")
something <- somefunction(mypreviousdata)
}
})
}
Other than saving to CSV, you might prefer a database or the user's cookies, or whatever.

Related

How can I insert text in ANY empty field of a layout in filemaker?

I would like to write a script which goes to the first field of my layout, then evaluate if it is empty or not; if yes, it inserts "n.s." [not specified] and if it is not empty, it goes to the next field. And so on until the last field of my layout. In the end, it makes either a beep or a window appears saying "all done" (but this last part is optional and I can already do it).
My goal is to have a button which activates this script only when I press on it.
Up until now, I could make my script go from one field to another, but it would not write anything in the empty field it met... Aditionnally, most of the written function need a named target field and I would like to be able to go automatically from one field to another without having to change the target field name myself.
Here is my script at the moment:
Go to Field [Select/perform; Layout#1::Field#1]
If [IsEmpty ( Get ( ActiveFieldName ) )]
Insert Text [Select; "n.s."]
Go to Next Field
End If
Beep
It beeps but it doesn't write anything...
Or do you see a better solution ?
Not sure why you would need this, but if necessary, you could do it this way:
Go to Next Field
Set Variable [ $start; Value:Get ( ActiveFieldName ) ]
Loop
If [ IsEmpty ( Get ( ActiveFieldContents ) ) ]
Insert Text [ “n.s.” ]
End If
Go to Next Field
Exit Loop If [ Get ( ActiveFieldName ) = $start ]
End Loop
Beep
Note that this is (purposefully) not committing the record. And of course, all fields on the layout (or at least the fields that you want to include in this process) must be included in the tab order.

Wipe / Delete / Clear Simple Response Text to Replace (not Concatenate)

In the nodejs actions on google library, calling .add(text), .ask(text), and .close(text) on the conversation concatenates that text onto the simple text response, i.e.
conv.add('hello');
conv.close('world');
// yields text response "hello world"
This is normally just fine. But, I'm hitting a case where I need to clear out everything that I've added onto the simple response text to replace it with some error handling response, i.e.
conv.add('hello');
// something went wrong, need to clear "hello" and replace
conv.ask('sorry, could you repeat your command?');
// yields text reponse "sorry, could you repeat your command?"
// *does not* yield "hello sorry, could you repeat your command?"
I cannot find a function on the conversation object that achieves this behavior. Is there a way I can manually clear out the responses in order to replace them with something new?
It looks like I can manually access the Response[] array on the conversation object and clear it out with an empty array. So, in the case of my example, I could do:
conv.add('hello');
conv.responses = []; // clears out the previously added "hello"
conv.ask('sorry, could you repeat your command?');
// yields text response "sorry, could you repeat your command?"

OR Formula in Word document not returning a value

I am working on a document where I need to be able to test multiple options in an if statement to see if one of them are true to decide if a paragraph displays on the document. I have been trying to figure out why my OR formula is not returning a value for me to test and I am not sure why it is not showing anything when it is updating.
I have inserted a field and added a formula within that field that I am hoping will work with my If statement to show the proper paragraph contens.
When I use an Or statement, even one as simple as { OR(1=1) } and update and toggle the field I get no result. From what I have read I should get a 1 or a 0, but I don't seem to get either of these results. The line just ends up blank. When I test it with my If formula it always shows the false result, even when the Or contains a true result.
The formula I am currently working with is:
{ IF{ OR("$event.eventType.name}" = "Birthday", "$event.eventType.name}" =
"Conference" } "Yes" "No" }
If I update and toggle the Or field it shows blank, no result either true or false, and makes the If formula show as false event on results where it should show true. As I mentioned above I even tried setting it to 1=1 and still could not get it to show as true. Not sure if there is something I am missing in working with the formula.
Any suggestions would be appreciated.
It's not clear from your post what $event.eventType.name is. Presumably it's a field generated by an Addin. In that case, you should be able to use something like:
{IF{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0}# 0}> 0 "Yes" "No"}
or:
{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0} \# "'Yes',,'No'"}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. If your fields are a kind of mergefield, you'll need to insert 'MERGEFIELD ' at the start of each one, thus:
{MERGEFIELD $event.eventType.name}

Cobol search function line sequential

This is my code.
SEARCH-RECORD.
PERFORM SEARCH-OPENING-PROCEDURE.
PERFORM SEARCH-CUSTOMER-RECORD.
PERFORM SEARCH-RECORDS
UNTIL CUST-NO = "0".
PERFORM SEARCH-CLOSING-PROCEDURE.
SEARCH-OPENING-PROCEDURE.
OPEN INPUT CUSTOMER-FILE.
SEARCH-CLOSING-PROCEDURE.
CLOSE CUSTOMER-FILE.
SEARCH-RECORDS.
PERFORM DISPLAY-ALL-FIELDS.
PERFORM SEARCH-CUSTOMER-RECORD.
ENTER-CUSTOMER-NO.
PERFORM ACCEPT-CUSTOMER-NO.
PERFORM RE-ACCEPT-CUSTOMER-NO
UNTIL CUST-NO NOT = SPACE.
ACCEPT-CUSTOMER-NO.
DISPLAY "ENTER CUSTOMER NO. (EX. C01)".
DISPLAY "ENTER 0 TO STOP".
ACCEPT CUST-NO.
INSPECT CUST-NO
CONVERTING LOWER-ALPHA
TO UPPER-ALPHA.
RE-ACCEPT-CUSTOMER-NO.
DISPLAY "CUSTOMER NO. MUST BE ENTERED!".
PERFORM ACCEPT-CUSTOMER-NO.
SEARCH-CUSTOMER-RECORD.
PERFORM ENTER-CUSTOMER-NO.
MOVE "N" TO RECORD-FOUND.
PERFORM FIND-CUSTOMER-NO
UNTIL RECORD-FOUND = "Y" OR CUST-NO = "0".
FIND-CUSTOMER-NO.
PERFORM READ-CUSTOMER-RECORD.
IF RECORD-FOUND = "N"
DISPLAY "CUSTOMER RECORD NOT FOUND"
PERFORM ENTER-CUSTOMER-NO.
READ-CUSTOMER-RECORD.
MOVE "Y" TO RECORD-FOUND.
READ CUSTOMER-FILE RECORD.
DISPLAY-ALL-FIELDS.
DISPLAY " ".
PERFORM DISPLAY-CUSTOMER-RECORD.
DISPLAY " ".
DISPLAY-CUSTOMER-RECORD.
DISPLAY " CUSTOMER NO.: " CUSTOMER-NO.
DISPLAY "1. CUSTOMER ID: " CUSTOMER-ID.
DISPLAY "2. CUSTOMER NAME: " CUSTOMER-NAME.
DISPLAY "3. CUSTOMER PRODUCT: " CUSTOMER-PRODUCT.
DISPLAY "4. CUSTOMER QUANTITY: " CUSTOMER-QUANTITY.
DISPLAY "5. CUSTOMER DATE: " CUSTOMER-DATE.
Just assume that I have complete records of C01,C02,C03,C04,C05.
My problem is that my CUSTOMER-FILE is in line sequential. So, whenever I try to search for a specific record like C04's record, it always show C01's record first, then C02's, C03's regardless of what I put in my search function. Is there any way that can do custom search? I don't know all the commands, thank you.
Here's why your logic always stops after looking at the first record: in READ-CUSTOMER-RECORD, you set your record-found flag without checking to see if you have a match (between the record you just read and the customer number you want). You need to keep reading until you reach the end of file (EOF) or you find the desired customer record. You need to detect the difference between "I didn't find it on this READ" and "I didn't find it at all."
So you want to change your logic to something like this. There are cleaner ways to code this, but it's the smallest change to what you have already:
SEARCH-CUSTOMER-RECORD.
PERFORM ENTER-CUSTOMER-NO.
MOVE "N" TO RECORD-FOUND.
MOVE "N" TO EOF-FLAG.
PERFORM FIND-CUSTOMER-NO
UNTIL RECORD-FOUND = "Y" OR CUST-NO = "0".
FIND-CUSTOMER-NO.
PERFORM READ-CUSTOMER-RECORD
UNTIL EOF-FLAG = "Y" OR RECORD-FOUND = "Y".
IF RECORD-FOUND = "N"
DISPLAY "CUSTOMER RECORD NOT FOUND"
PERFORM ENTER-CUSTOMER-NO.
READ-CUSTOMER-RECORD.
READ CUSTOMER-FILE RECORD
AT END
MOVE "Y" TO EOF-FLAG.
IF EOF-FLAG = "N"
IF CUSTOMER-NO = CUST-NO
MOVE "Y" TO RECORD-FOUND.
If you reach the end of the file, CUSTOMER-NUMBER doesn't have a well-defined value. That's why we have to guard the test with IF EOF-FLAG = "N". Again, there are other ways to do this, but I'm trying to keep it simple.
A general note on your coding style: there are places where you have redundant code that can be simplified and improved. Rather than performing SEARCH-CUSTOMER-RECORD and then displaying the results in SEARCH-RECORDS, you can recode it so that SEARCH-RECORDS does the search and then the display.
Update
One more very important point: when you start a new search, you need to close and re-open CUSTOMER-FILE. (This has the effect of moving the file pointer back to the beginning of the file.) If you don't do this, your second search will start reading the file from the point you left off, or from the end of file.
There are other file organizations that you will learn about that make this step unnecessary: they allow you to use the START statement.

Is there any way when I choose an option not to clear previously typed data in the input

The problem is this:
In my programme at first the user gets options for a first name - so hopefully he likes something from the options and he chooses it -so far everything is OK!
But then when he types space he starts receiving options for second name and a if he likes something and chooses it - then the Autocomplete just erases the first name. Is there any way I can change that?
hello Rich thank you very much or your response - now i've decided to change my task and here is what I made when a user types for example I character i get all the first names that start with I- so far no problem! ANd when he types the white space and K for example I make request to my web service that gets the middle names that starts with K or the last names that start with K (one of them should start with K for Iwelina), so in this case for Iwelina Ive got RADULSKA KOSEWA and KOSEWA NEDEWA! For the source of autocomplete I concatenate iwelina with (radulska kosewa)and iwelina with (KOSEWA NEDEWA) so at the end I've got IWELINA IELINA RADULSKA KOSEWA and IWELINA KOSEWA NEDEWA!!! the only problem is that when i type Iwelina K i get only IWELINA KOSEWA NEDEWA!!!here is the code for autocomlete
$('#input').autocomplete({
source: function(request, response) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term, " "));
var data = $.grep( srcAutoComp, function(value) {
return matcher.test( value.label || value.value || value );
});
response(data);
}
});
if you know how i can change it I will be glad for the help
I don't understand how, when the user begines to type the second name, he's getting results that are only the last name. For example, if he types "Joh" and selects "John" from the options, and then continues to type "John Do", then how is it possible that your drop down gives him results for only the last name, like "Doe"?
At any rate, assuming this is truly happening, you could just combine all combinations of first and last names in your source data and that will show "John Doe" in the drop down when the user types "Joh" selects "John" and then continues to type "John Do".
Another way to do this is with a complicated change to the search and response events to search after a space if it is there, and recombine it with the first string after the search for the last name is complete. If you give me your source data, I could put something together for this.

Resources