How to update gtable at gWidget in R? - r

I'm struggling to update the table data in the following code for GUI. It works to add each new request to the previous, so that it doesn't fit the screen, while I need to replace old request with the new one. Thanks! A.
require ( gWidgets )
options ( guiToolkit="RGtk2" )
window <- gwindow ( "Pilot>>" , visible = FALSE, horizontal = FALSE )
paned <- gpanedgroup ( cont = window )
group <- ggroup ( cont = paned, horizontal = FALSE )
glabel ( "FPC:" , cont = group )
entry <- gedit ( "" , cont = group )
entry [ ] <- actfpc$CURFPC ##list of codes for auto-filling
search_button <- gbutton ( "Go!" , cont = group )
addSpring ( group )
frame <- gframe ( "Supply:" , cont = paned , horizontal = FALSE,use.scrollwindow=TRUE )
addHandlerChanged ( search_button , handler = function ( h , ... ) {
##Data subset for entered value
a<-skulist[skulist$FPC==svalue(entry),]
a<-a[c("X_id","FPC","STATUS","COMMENT","DCTR","DCSTOCK")]
tbl <- gtable ( a , cont = frame, expand=TRUE )
} )
size ( frame) <- c ( 950 , 250)
visible ( window ) <- TRUE

Related

Modify cell in a R DT::datatable based on previous row

I have a shiny app where I would like to modify the data displayed and/or the attributes of a cell based on the value of the same cell in the previous row.
In my code I have formatted whole rows based on the value of data[0] in rowCallback.
output$result <- DT::renderDataTable(tabledata(),
class = c('compact'),
rownames = FALSE,
server = FALSE,
escape = TRUE,
extensions = options = list(
rowCallback=JS("
function (row, data, index) {
var string=data[1], substring = 'sub total';
if (data[0]=='Grand Total') {
$(row).css('background-color', '#DEDEDE'), $(row).css('font-weight', 'bold') ;
}
else if (data[0].includes('sub total')) {
$(row).css('font-weight', 'bold');
}
}"
)
)
)
Can I achieve a modification of the data[0] cell based on the value of the same cell in the previous row using one of the callback functions?
So I changed tack and used the following drawCallback call
drawCallback=JS(" function ( settings ) {
var api = this.api();
var mydata = api.rows( {page:'current'} ).data();
var last=null;
api.column(0,{page:'current'}).data().each( function ( value, index ) {
if ( value == last) {
mydata[index][0] = ''
api.rows({ page: 'current' }).invalidate();
}
last=value;
});
}"
)

Coalesce and trim function

I am trying to execute the below script
CREATE VIEW JOES.WEBSKULOOKUPVIEW (
STYLEID ,
STYLENAME ,
DISPLAYSTYLENUMBER ,
B2BSTYLE ,
WEBPRODDESCR ,
WEBSTYLENAME ,
WEBSKUNUMBER ,
SUPPLIERNAME ,
SKUID ,
SKUNUMBER ,
SKUACTIVESTATUS ,
B2BSKU ,
SKUSIZE ,
SKUCOLOUR ,
WPSTYLEID )
AS
SELECT DISTINCT ESTYLE.STYLEID, ESTYLE.STYLENAME, ESTYLE.DISPLAYSTYLENBR, ESTYLE.B2BSTYLE, WPROD.H1SJXT, WPSTYLE.H2AMNA,
WPSKU.H3DINB, SUPP.SUPPLIERNAME, ESKU.SKUID, ESKU.SKUNUMBER, ESKU.SKUACTIVESTATUS, ESKU.B2BSKU,
(COALESCE(TRIM(FIRSTSIZE.SHORTSCALEVALUE) , '') || COALESCE(TRIM(', ' || SECSIZE.SHORTSCALEVALUE), '')) AS "SIZE",
STYLEACTUALCOLOUR.SPECIFICCOLOURNAME , STYLE.STYLEID
FROM ENTERPRISE.STYLE ESTYLE, ENTERPRISE.SUPPLIER SUPP, MWWDATA.DGH1CPP WPROD,
MWWDATA.DGH2CPP WPSTYLE, MWWDATA.DGH3CPP WPSKU, ENTERPRISE.STOCKKEEPINGUNIT ESKU, ENTERPRISE.STYLEACTUALCOLOUR STYLEACTUALCOLOUR,
ENTERPRISE.STYLE STYLE, ENTERPRISE.STYLEACTSTATUS STYLEACTSTATUS, ENTERPRISE.STYLEACTSTATUS SKUACTSTATUS, ENTERPRISE.SKUSIZE SKUSIZE
LEFT OUTER JOIN ENTERPRISE.SIZESCALEVALUE FIRSTSIZE ON FIRSTSIZESCALEID = FIRSTSIZE.SIZESCALEID AND FIRSTSIZESCALEOBJI = FIRSTSIZE.SIZESCALEOBJID
LEFT OUTER JOIN ENTERPRISE.SIZESCALEVALUE SECSIZE ON SECSIZESCALEID = SECSIZE.SIZESCALEID AND SECSIZESCALEOBJID = SECSIZE.SIZESCALEOBJID
WHERE ESTYLE.DEFAULTSUPPLIERID = SUPP.SUPPLIERID AND
SUPP.VENDORENTITYCODE = WPSTYLE.H2RWCO AND
ESTYLE.STYLEUSERCODE = WPSTYLE.H2AICD AND
WPSTYLE.H2SCNS = WPROD.H1SCNS AND
WPROD.H1SCNS = WPSTYLE.H2SCNS AND
WPSTYLE.H2SCNS = WPSKU.H3SCNS AND
WPSTYLE.H2RWCO = WPSKU.H3RWCO AND
WPSTYLE.H2AICD = WPSKU.H3AICD AND
WPSKU.H3DINB = CAST (ESKU.SKUNUMBER AS DECIMAL) AND
STYLE.STYLEID = ESKU.STYLEID AND
ESKU.STYLEID = STYLEACTUALCOLOUR.STYLEID AND
ESKU.ACTUALCOLOUROBJID = STYLEACTUALCOLOUR.ACTUALCOLOUROBJID AND
STYLE.STYLEACTIVESTATUS = STYLEACTSTATUS.STYLEACTIVESTATUS AND
ESKU.SKUACTIVESTATUS = SKUACTSTATUS.STYLEACTIVESTATUS AND
ESKU.SKUID = SKUSIZE.SKUID AND SKUACTIVESTATUS NOT IN ('P', 'D') ;
And it throws the error as mentioned below.
(COALESCE(TRIM(FIRSTSIZE.SHORTSCALEVALUE) , '') || COALESCE(TRIM(', ' || SECSIZE.SHORTSCALEVALUE), '')) AS "SIZE",
*
ERROR at line 20:
ORA-12704: character set mismatch
But that is the syntax for coalesce and trim.
So what possible changes should I make to solve this issue.

ZF2 Doctrine with Symfony < OR null query

How do I write this "WHERE" condition in a way which is compatible with Doctrine?
( ( `translations_es_google`.`translation_date` < `translations_masters`.`translation_date` ) OR ( `translations_es_google`.`translation_date` is null ) )
What I have tried (unsuccessfully) are:
$query1
->andWhere('((t.translationDate < m.translationDate) OR (t.translationDate is NULL))');
$query1
->andWhere('(t.translationDate < m.translationDate) OR (t.translationDate is NULL)');
Table alias for the Doctrine query are
t represents the table translations_es_google
m represents the table translations_masters
When I remove this "andWhere" condition the rest of the QueryBuilder query executes as expected.
The query I am trying to execute is
SELECT
`translations_masters`.`translation_key` , `translations_masters`.`text_domain` , `translations_masters`.`translation_date`
FROM
`translations_masters`
LEFT JOIN
`translations_es_google` ON ( ( `translations_masters`.`text_domain` = `translations_es_google`.`text_domain` ) AND ( `translations_masters`.`translation_key` =`translations_es_google`.`translation_key` ) )
WHERE
`translations_masters`.`language_iso` NOT LIKE 'es-Google' AND ( ( `translations_es_google`.`translation_date` < `translations_masters`.`translation_date` ) OR ( `translations_es_google`.`translation_date` is null ) )
GROUP BY
`translations_masters`.`translation_key` , `translations_masters`.`text_domain`
ORDER BY
`translations_masters`.`translation_date` ASC
As requested the QueryBuilder version of this query is:
$query1 = $this->entityManager
->createQueryBuilder()
->select('m.textDomain , m.translationKey , m.translationDate , m.translationDate AS translationMasterDate , t.translationDate')
->from(
'AMDatabase\Entity\TheVerse\Translations' . $explode1 . $explode2,
't'
)
->leftJoin(
'AMDatabase\Entity\TheVerse\TranslationsMasters',
'm',
Join::WITH,
'(m.textDomain = t.textDomain) AND (m.translationKey = t.translationKey)'
)
->groupBy('m.textDomain , m.translationKey')
->orderBy(
'm.translationDate',
'ASC'
)
->setMaxResults('1');
$query1
->andWhere(
$query1->expr()
->notLike(
'm.languageIso',
':languageIso'
)
)
->setParameter(
'languageIso',
$value
);
$query1->andWhere(
$query1->expr()->orX(
't.translationDate < m.translationDate',
't.translationDate IS NULL'
)
);
$result1 = $query1->getQuery()
->getArrayResult();
The output of $query1->getQuery()->getSQL() is
SELECT
t0_.text_domain AS text_domain_0, t0_.translation_key AS translation_key_1, t0_.translation_date AS translation_date_2, t0_.translation_date AS translation_date_3, t1_.translation_date AS translation_date_4
FROM
thev1010_theverseoftheday.translations_es_google t1_
LEFT JOIN
thev1010_theverseoftheday.translations_masters t0_ ON ((t0_.text_domain = t1_.text_domain) AND (t0_.translation_key = t1_.translation_key))
WHERE
t0_.language_iso NOT LIKE ? AND (t1_.translation_date < t0_.translation_date OR t1_.translation_date IS NULL)
GROUP BY
t0_.text_domain, t0_.translation_key
ORDER BY
t0_.translation_date ASC
LIMIT 1
The ? value is 'es-Google'
The output of $query1->getQuery()->getDQL(); is
SELECT
m.textDomain , m.translationKey , m.translationDate , m.translationDate AS translationMasterDate , t.translationDate
FROM
AMDatabase\Entity\TheVerse\TranslationsEsGoogle t
LEFT JOIN
AMDatabase\Entity\TheVerse\TranslationsMasters m WITH (m.textDomain = t.textDomain) AND (m.translationKey = t.translationKey)
WHERE
m.languageIso NOT LIKE :languageIso AND (t.translationDate < m.translationDate OR t.translationDate IS NULL)
GROUP BY
m.textDomain , m.translationKey
ORDER BY
m.translationDate ASC
The ? value is 'es-Google'
How about orX expression?
You can try it this way:
$query1->andWhere(
$query1->expr()->orxX(
't.translationDate < m.translationDate',
't.translationDate IS NULL'
)
);
orX gives you the ability to add multiple conditions, separated by comma.
You can also separate your orX condition to its own variable and pass everything added to it to andWhere condition.

Corona Button not passing focus to scrollView

I am having an issue with scrolling when buttons are on the scrollView. The problem is the issue of events not being handled properly. All attempts to pass focus to the scrollView have proven fruitless. An observation I have made is that in this following code, it is not printing back to me, this is even after I was scrolling correctly without the buttons in the way of it.
local function scrollListener( event )
local phase = event.phase
if ( phase == "began" ) then print( "Scroll view was touched" )
elseif ( phase == "moved" ) then print( "Scroll view was moved" )
elseif ( phase == "ended" ) then print( "Scroll view was released" )
end
-- In the event a scroll limit is reached...
if ( event.limitReached ) then
if ( event.direction == "up" ) then print( "Reached top limit" )
elseif ( event.direction == "down" ) then print( "Reached bottom limit" )
elseif ( event.direction == "left" ) then print( "Reached left limit" )
elseif ( event.direction == "right" ) then print( "Reached right limit" )
end
end
return true
end
Here is the actual code being used for the scene:
function scene:enterScene(event)
--local yell=audio.play(ahhh, {channel=1, loops=0, fadein=0})
--Creating the Background
local background=display.newImageRect("background.png", 320, 580)
background.x=160
background.y=240
--Creating the scroll view
local scrollView = widget.newScrollView
{
top = 10,
left = 10,
width = 300,
height = 500,
scrollWidth = 300,
scrollHeight = 500,
horizontalScrollDisabled = true,
listener = scrollListener
}
local button = {}
local yCount = 0
for i = 1 , 11 do
button[i] = widget.newButton{
label = "Button " .. i,
left = 0,
id = button[i],
top = yCount,
width = 300,
height = 100,
defaultFile = "menuButton.png",
onEvent = handleButtonEvent
}
yCount = yCount + 100
scrollView:insert(button[i])
end
--local background=display.newRect(160, 270, 320, 510)
--scrollView:insert( background )
local menu=display.newImageRect("menu2.png", 90, 50)
menu.x=50
menu.y=-15
function menu:touch(event)
if event.phase=="began" then
--local illBeBack=audio.play(terminator,{channel=1, loops=0, fadein=0})
display.remove(menu)
display.remove(taskBar)
display.remove(background)
taskBar = nil
background = nil
menu = nil
storyboard.gotoScene("menu")
end
return true
end
menu:addEventListener("touch", menu)
end
--Button Event Handler
local function handleButtonEvent( event )
local phase = event.phase
if ( phase == "moved" ) then
local dy = math.abs( ( event.y - event.yStart ) )
-- If the touch on the button has moved more than 10 pixels,
-- pass focus back to the scroll view so it can continue scrolling
if ( dy > 10 ) then
scrollView:takeFocus( event )
end
end
return true
end
Try passing the event.phase into scrollView like this:
scrollView:takeFocus(event.phase)
The problem was solved by removing 'local' from the 'handleButtonEvent' and 'scrollListener' functions, along with removing 'local' from the 'scrollView' widget
So it appears that in corona, or at least the program I am making, that globals must be used a lot more than what they should be, unless someone else has a solution.

Instantiation of reference classes within reference classes - problems with lock() and immutability

I have come across some behaviour from R reference classes I would like to work around. In the following code, reference class B has two fields of reference class A in it.
These fields in B appear to be instantiated (possibly twice) with a zero-argument (default) versions of reference class A before B's initialize() method is called. These instances are then replaced with the correct versions of instance A during B's initialization process. The problem is that if I use lock() from B's instance generator, the initial empty instantiation's of A cannot be replaced in B. Another problem is that reference class A needs a default value in initialize [or a missing(c) test].
Help - suggestions - etc. appreciated.
A <- setRefClass('A',
fields = list(
count = 'numeric'
),
methods = list(
initialize = function (c=0) {
cat('DEBUG: A$initialize(c); where c='); cat(c); cat('\n')
count <<- c
}
)
)
instance.of.A <- A$new(10)
str(instance.of.A)
B <- setRefClass('B',
field = list(
a = 'A',
b = 'A'
),
methods = list(
initialize = function(c) {
a <<- instance.of.A
b <<- getRefClass('A')$new(c)
}
)
)
instance.of.b <- B$new(100)
str(instance.of.b)
Here are two possible solutions:
Don't set fields attribute:
B <- setRefClass('B',
methods = list(
initialize = function(c) {
.self$a = instance.of.A
.self$b =getRefClass('A')$new(c)
}
)
)
Set fields, but use the ANY class:
B <- setRefClass('B',
field = (a="ANY", b="ANY"),
methods = list(
initialize = function(c) {
a <<- instance.of.A
b <<- getRefClass('A')$new(c)
}
)
)
The downside of both these solutions is the type isn't enforced in a and b, i.e.
B$a = "Fred"
is now possible.
Drawing on the above, the solution I am using is (a little long because of the type checking):
A <- setRefClass('A',
fields = list(
count = function(x) {
if (!missing(x)) {
if(class(x) != 'numeric')
stop('Class A: count set by non-number')
.self$count.private <- x
}
.self$count.private
}
),
methods = list(
initialize = function (c=0) {
cat('DEBUG: A$initialize(c); where c='); cat(c); cat('\n')
count <<- c
}
)
)
instance.of.A <- A$new(10)
str(instance.of.A)
B <- setRefClass('B',
field = list(
a = function(x) {
if (!missing(x)) {
if(!inherits(x, 'envRefClass') || class(x)[1] != 'A')
stop('Class B: expecting instance of class A')
.self$a.private <- x
}
.self$a.private
},
b = function(x) {
if (!missing(x)) {
if(!inherits(x, 'envRefClass') || class(x)[1] != 'A')
stop('Class B: expecting instance of class A')
.self$b.private <- x
}
.self$b.private
}
),
methods = list(
initialize = function(c) {
a <<- instance.of.A
b <<- getRefClass('A')$new(c)
}
)
)
instance.of.b <- B$new(100)
str(instance.of.b)

Resources