Can readLines(prompt = ...) be used in any way in shiny?
Suppose the following: in the server, inside a renderPrint component I will use shinijs::display("takeInput). This GUI component takes input from the user, so I will pass the input to a function by means of the function call. Afterwards, the function calls another function and sends the input to that function. The input will be received and tested by the second function. The result of the test will be returned to the first function which will return it to the server. Please see below:
Is there another way to do this? A simpler way? I do not see the way of doing it by just using readLine(promp = ..) in the second function. I do not see how this can be compatible with shiny.
ui{
selectInput("xxxxx")
verbatimTextOutput(
}
source(program containing functionName)
source(program containing another function name)
functionName <- function(parameters, takeInput){
functionName2 <- anotherFunctionName(parameters, takeInput)
functionName2 <- valueOfFunctionName2
if(functionName2 == xx){
dosomthing
return the value to the server
list(functionName2 = functionName2)
}
anotherFunctionName<- function(parameters, takeInput){
if(takeInput == something){
return the value of anotherFunctionName to functionName which will return it to the server
valueOfFunctionName2
}
}
Related
I've got a method in UsersController
public function addMailbox($data)
{
$this->LoadModel('Mailbox');
$mailbox = $this->Mailbox->newEntity();
$mailbox->username = $data('username');
$mailbox->name = $data('name');
if ($this->Mailbox->save($mailbox)) {
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Error'));
}
, the code works fine when pasted into the add() method, but after using
$this->addMailbox($this->request->getData());
all i get is
error: Function name must be a string
Any ideas?
You've got the wrong syntax for accessing arrays in PHP, use square brackets:
$mailbox->username = $data['username'];
$mailbox->name = $data['name'];
The way you've got it, it's trying to call a function with the variable named in $data, but $data is an array not a string (see Variable functions for more info on that).
Also you shouldn't set user input on $mailbox properties directly - this bypasses validation. Instead just stick $data in newEntity():
public function addMailbox($data)
{
$this->loadModel('Mailbox'); // This also is not required if this function is inside the MailboxController
$mailbox = $this->Mailbox->newEntity($data);
if ($this->Mailbox->save($mailbox)) {
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Error'));
}
def getMessage1(self, id, queueName):
uuid = id
def onMessage(ch, method, properties, body):
if uuid in body:
requeued_messages = self.channel.stop_consuming()
return body
self.channel.basic_consume(consumer_callback = onMessage, queue = queueName, no_ack = True)
self.channel.start_consuming()
return onMessage(ch, method, properties, body)
#global name 'ch' is not defined
I am trying to define two function as shown in the code. I am try to return body to the inner function and I also want to the same body to return to my outer function i.e getMessage1.
But this above code returns me with
"function onMessage at 0x0000000006642128" not the "body"
and also I want my inner function to get the come out of the loop only when the uuid is present in the body.
Returned body is a string
here is the basic_consume function that I am using
def basic_consume(self, consumer_callback,
queue='',
no_ack=False,
exclusive=False,
consumer_tag=None,
arguments=None):
"""Sends the AMQP command Basic.Consume to the broker and binds messages
for the consumer_tag to the consumer callback. If you do not pass in
a consumer_tag, one will be automatically generated for you. Returns
the consumer tag.
For more information on basic_consume, see:
http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume
:param method consumer_callback: The method to callback when consuming
with the signature consumer_callback(channel, method, properties,
body), where
channel: pika.Channel
method: pika.spec.Basic.Deliver
properties: pika.spec.BasicProperties
body: str, unicode, or bytes
In order for getMessage1 to return the body from onMessage, you need to return the call of onMessage. As it stands now, you're returning a function.
Consider these two examples:
def foo():
def bar():
return "This is from Bar"
return bar()
print foo()
Result:
This is from Bar
vs
def foo():
def bar():
return "This is from Bar"
return bar
print foo()
Result:
<function bar at 0x0270E070>
You get the message function onMessage at 0x0000000006642128 because your return statement return onMessage returns the function onMessage without evaluating the results. If you want to evaluate the function you need something like return onMessage(channel, method, properties, body) with the values/variables you want evaluated inside the parentheses. Below is a working example of an inner and outer function:
def sumOfSquares(a,b):
def square(c):
return (c*c)
return square(a)+square(b)
print(sumOfSquares(2,3))
I don't see a loop in either function. Please provide more information on the second part of your question.
partial void Query1_PreprocessQuery(string Filter1, ref IQueryable<Type> query)
{
//how can I loop through the query and add data to a custom list
}
Generally speaking, the _PreprocessQuery method is for defining the contents of the query and not doing anything with those contents (which would be Post processing). So a simple method might read:
partial void Query1_PreprocessQuery(string Filter1, ref IQueryable<Type> query)
{
query = query.Where(x => x.FilterColumn == Filter1);
}
This is happening on the server side so even if you did intercept the results, I think it would be tricky to get any list you created back to the client side.
Once the query results have been passed to the client screen, you can then loop through the query and use the contents however you like, for example using Screen Property methods like Query1_Loaded or Collection methods like Query1_Changed depending on what you're trying to achieve. Untested code, but something like this:
partial void Query1_Loaded(bool succeeded)
{
// Loop through the rows on the screen ...
foreach (IEntityObject rowData in this.Query1)
{
// Reference individual values like this ...
string FilterResult = rowData.Details.Properties["FilterColumn"].Value.ToString()
}
}
}
I am trying to create a cf component to proxy another one. At the moment the code looks like this: (stripped down for the sake of example):
public MyFuseboxProxy function init( Required any myFb ){
variables.myFusebox = arguments.myFb;
return this;
}
this.do = variables.proxy;
private any function proxy(){
var local.functionName = getFunctionCalledName();
var local.function = variables.myFusebox[local.functionName];
var local.returnVal = local.function( arguments );
...
}
As you can see, it's quite straight forward. I pass in my target object at initialisation then use the proxy method to intercept function calls. I am using cfscript, and don't want to use cfinvoke, so am using this approach.
I then call the proxy as follows:
var local.proxy = new ab.MyFuseboxProxy( myFusebox );
var local.dump = local.proxy.do ( action='display.body', contentvariable="body" );
However, when I execute the above code I get the following error:
The ACTION argument passed to the do function is not of type string.
If the component name is specified as a type of this argument, it is possible that either a definition file for the component cannot be
found or is not accessible.
The error occurred in C:/ColdFusion10/cfusion/wwwroot/fusebox5/myFusebox.cfc: line 301
The error is reported on the target component, so it seems like the function is being called, and the arguments passed through, but the type is not being preserved/recognised as a String.
Can anyone advise what I am doing wrong or how I can preserve the argument types?
Yup, I suspect instead of this:
var local.returnVal = local.function( arguments );
You mean this:
var local.returnVal = local.function(argumentCollection=arguments );
Your current code is passing the arguments as the first argument, rather than passing them as they were originally passed in.
Here's basically what I want to accomplish:
{exp:plugin1:method arg="{exp:plugin2:method}"}
I’ve tried a number of different approaches.
Approach 1:
{exp:plugin1:method arg="{exp:plugin2:method}"}
Result: Plugin1->method’s arg parameter value is the string, {exp:plugin2:method}, and it’s never parsed.
Approach 2:
My understanding of the parsing order suggests that this might have different results, but apparently it does not.
{preload_replace:replaced="{exp:plugin2:method}"}
{exp:plugin1:method arg="{replaced}"}
Result: The arg parameter has the same value as approach 1.
Approach 3:
First I define a snippet (snip), whose content is:
{exp:plugin2:method}
Then in the template:
{exp:plugin1:method arg="{snip}"}
Result: Same as approaches 1 and 2.
Approach 4:
Noting that plugins are processed in the order they appear, I have even tested simply placing an instance of {exp:plugin2:method} before the {exp:plugin1:method} call. My thinking is that I could wrap this first call in a regex replacement plugin in order to suppress output, but that it would trigger Plugin2’s parsing first.
{exp:plugin2:method}
{exp:plugin1:method arg="{exp:plugin2:method}"}
Result: Plugin1->method’s arg parameter value is the temporary hash placeholder for Plugin2->method’s output (MD5 I believe) that the Template class reserves until later.
Interesting approach. However, this can be achieved more simply like this:
{exp:plugin1:method arg="{exp:plugin2:method}" parse="inward"}
I have a workaround, but I'll wait a while to see if a better solution comes up before I accept my own answer. The workaround is to wrap plugin1 with plugin2 and replace template tags referring to its methods within the tagdata. Note that this requires a parse="inward" parameter on the plugin2 call.
In the template:
{exp:plugin2 parse="inward"}
{exp:plugin1:method arg="{someplugin2method}"}
{/exp:plugin2}
In the plugin class:
static $public_methods;
function __construct() {
// Actual construction code omitted...
if(($tagdata = $this->EE->TMPL->tagdata) !== false && trim($tagdata) !== '') {
if(!isset(self::$public_methods)) {
self::$public_methods = array();
$methods = get_class_methods($this);
foreach($methods as $method) {
if($method == get_class($this) || $method == '__construct') {
continue;
}
$reflection = new ReflectionMethod(get_class($this), $method);
if($reflection->isPublic()) {
self::$public_methods[] = $method;
}
}
self::$public_methods = implode('|', self::$public_methods);
}
$tagdata = preg_replace_callback('/\{(' . self::$public_methods . ')\}/',
array($this, 'tagdata_callback'), $tagdata);
$this->return_data = $tagdata;
}
}
private function tagdata_callback($matches) {
$method = $matches[1];
return $this->$method();
}
Caveats:
This can make for messier templates.
Maintaining a list of public methods apparently requires Reflection which is not available in PHP 4. You can, of course, maintain a list of expected methods manually.