Problem with Data.table R in shiny

shiny
shinydashboard

#1

I have a very basic question why does

inputfile[!(GSTINUIN %>% is.na()),.(InvoiceDate=unique(InvoiceDate),
                                    Amount=sum(Amount),
                                 PlaceOfSupply=unique(PlaceOfSupply),
                                 ReverseCharge=unique(ReverseCharge),
                                 InvoiceType=unique(InvoiceType),
                                 ECommerceGSTIN=unique(ECommerceGSTIN)
                                 
                                 ),by=.(GSTINUIN,InvoiceNumber,CGSTRate=CGSTRate*2)
                                ][
                                ,.(InvoiceDate,
                                   Amount=sum(Amount),
                                   PlaceOfSupply,
                                   ReverseCharge,
                                   InvoiceType,
                                   ECommerceGSTIN,
                                   CGSTRate
                                    )
                                ,.(GSTINUIN,InvoiceNumber)
                                 ]

works on R console but the same code

inputfile()[!(GSTINUIN %>% is.na()),.(InvoiceDate=unique(InvoiceDate),
                       Amount=sum(Amount),
                       PlaceOfSupply=unique(PlaceOfSupply),
                       ReverseCharge=unique(ReverseCharge),
                       InvoiceType=unique(InvoiceType),
                       ECommerceGSTIN=unique(ECommerceGSTIN)

    ),
    by=.(GSTINUIN,InvoiceNumber,CGSTRate)
    ][
        ,.(InvoiceDate,
           Amount=sum(Amount),
           PlaceOfSupply,
           ReverseCharge,
           InvoiceType,
           ECommerceGSTIN,
           CGSTRate
        )
        ,.(GSTINUIN,InvoiceNumber)
        ]

Doesn’t work in reactive context. I have been facing this issue since morning and I am not sure what am I doing wrong here. Is there anything that I am missing.

I have uploaded the file in google mailing list. Here I don’t see any option to upload the zip file. Kindly look into it.

I just want to understand what am I doing wrong conceptually.


#2

What is the error that’s generated when you try to use the code in the reactive context?


#3

object ‘GSTINUIN’ not found

I don’t know why is it happening.


#4

you can download the entire project just by going to this link

https://github.com/Rdatatable/data.table/issues/2443

and it is nothing big just manipulating some basic excel file. and I am not able to write the data.table code.


#5

Are you creating the “GSTINUIN” object in the Shiny script? If you are getting an object not found, it seems like the “GSTINUIN” object is not being created when the Shiny application executes.

If GSTINUIN is in your environment, when you run the application interactively it will be found. However, when you run it as an application, a new environment is created where GSTINUIN may not exist.


#6

Looking at the source code in the link, @Anantadinath I think the issue is that identified by @kentm. You don’t create the GSTINUIN object inside any of the Shiny app code. How did you create GSTINUIN originally? I’d replicate whatever you did, either in app.R but outside ui or server logic, or build it directly in to the server logic if you need to.


#7

I am very very sorry for not being descriptive enough

I am trying to create a shiny app for my team where they can upload an excel file in a specific format and then get the data generated in a different format. Is write simple and i was able to write the code as well.

But somehow that doesn’t work in shiny context.

GSTINUIN is nothing but a column name that i have defined.

It should work everything being equal.

In fact

DT[, somecolumn]

Its a valid command on r console but

DT()[, somecolumn]

Is not a valid command in r shiny

DT[, “somecolumn”]

This again is a valid command in r shiny

So i am a bit confused. I have also posted the entire project; since there is nothing to hide, on shiny mailing list and on r data table issues.

If you want you can download it from any of those places. I have just posted it today so you should not have problem finding it.

It also includes the file that i want my team to upload.

Please check the code at least one its not big. I don’t claim to be an expert. I just want to know why does one works and other doesn’t. I want to understand it so that i can gain a deeper insight. It will helpful in future mor than the code itself

Please do reply. Thanks


#8

Having looked at the code, it doesn’t look like you ever say that rowdata() is a data.table. By default read_excel() will return a tibble, not a data.table, and they behave differently (e.g. the data.table syntax doesn’t work on a tibble.


#9

Let me check but just for simplicity i have added the project file in it where you will find the file in question.

If you read it with read excel and change it to data.table

You can just run the code.

But give me a minute let me try it might work


#10

I think you need to explicitly convert the output from read_excel() to a data.table inside the Shiny app, at the moment you don’t, so your [] syntax will be trying to do “normal” data.frame subsetting on the tibble and not operating in the way that data.tables do.


#11

Yes yes yes

Thank you very very very much for finding this it worked.

It seems like i was missing the point a very basic error. Sorry for so much trouble.

Thanks again