OHDSI / CohortDiagnostics

An R package for performing various cohort diagnostics.
https://ohdsi.github.io/CohortDiagnostics
40 stars 45 forks source link

CohortDiagnostics - R Shiny app throws an error when Visit Context is selected #1051

Closed ssivarama closed 1 week ago

ssivarama commented 1 year ago

Hi,

After launching the R shiny app using launchDiagnosticsExplorer, when I click on the Visit Context tab, I am seeing the following error

Error in .jcall("java/lang/Class", "Ljava/lang/Class;", "forName", cl, : RcallMethod: cannot determine object class SELECT visit_context.*, standard_concept.concept_name AS visit_concept_name FROM main.visit_context visit_context INNER JOIN main.concept standard_concept ON visit_context.visit_concept_id = standard_concept.concept_id WHERE database_id in ('iqvia_ambulatory_emr') AND cohort_id in (73); Warning: Error in ._jobjRef_dollar: no field, method or inner class called 'parent' 100: stop 99: ._jobjRef_dollar 98: $.Throwable 96: cnd_some 95: cnd_inherits 94: 93: stop 92: 91: stop 90: value[[3L]] 89: tryCatchOne 88: tryCatchList 87: tryCatch 86: do 85: hybrid_chain 84: renderFunc 83: output$DiagnosticsExplorer-visitContext-visitContextTable 2: shiny::runApp 1: CohortDiagnostics::launchDiagnosticsExplorer

I am attaching a screenshot for your reference. Can you please help in resolving this issue. Thanks. rshiny_app_visit_context_error rshiny_app_visitcontext_error.txt

azimov commented 1 year ago

Hi @ssivarama thanks for posting this issue.

This could be caused by a number of issues related to your environment or data model. This looks like CohortDiagnostics version 3.1.2 - we have since moved our shiny app to a separate package (OhdsiShinyModules) if updating and using this package (your results data should be compatible with it).

Other than this the issue may be related to your data model or possibly your java version or database drivers (if working with postgresql).

ssivarama commented 1 year ago

Hi Jamie,

I tested the Java dependency using the below code

install.packages("SqlRender") SqlRender::translate("a", "postgresql") ## Above code ran fine without any issues

Data is hosted on Redshift and JDBC Driver Version: RedshiftJDBC42-2.1.0.9.jar

azimov commented 1 year ago

Hmm, I'm assuming that your results are inside the sqlite file produced.

Can you run the following code and let me know what error (if any) comes back?


# Set to your connection details 

connection <- DatabaseConnector::connect(dbms = "sqlite", server = "MergedCohortDiagnosticsData.sqlite")
sql <- "SELECT visit_context.*,
standard_concept.concept_name AS visit_concept_name
FROM main.visit_context visit_context
INNER JOIN main.concept standard_concept
ON visit_context.visit_concept_id = standard_concept.concept_id
WHERE database_id in ('iqvia_ambulatory_emr')
AND cohort_id in (73);"

DatabaseConnector::renderTranslateQuerySql(connection, sql)

This will just execute the above query but do so in a way that should produce a message that will be easier to debug.

I'm expecting that the schema wasn't created correctly or it is corrupted in some way.

ginberg commented 10 months ago

has this error been solved by anyone? We are also experiencing this issue, both on shinyapps.io and Posit Connect

ablack3 commented 10 months ago

I don't understand why we need java to run the cohort diagnostics shiny app. Querying sqlite from R does not require java. We shouldn't need to use sqlrender to translate sql because there is only one database backend (sqlite), right? So why do we need java to display cohort diagnostics results?

azimov commented 10 months ago

The use of Java will likely be for SqlRender which is required to translate sql from OHDSI/MS sequel server to sqlite.

However, I have confirmed this is working on our Posit Connect instance and have previously had apps that use the SqlRender/Sqlite set up on shinyapps.io so this is difficult for me to reproduce.

ablack3 commented 10 months ago

Ah ok. Do you support multiple database backends for the shiny app?

Yea I have not been able to reproduce the error either but I know more than one person has experienced it.

egillax commented 8 months ago

Hi @ablack3 , @azimov , @ginberg

I have made a reprex in the following docker container:

https://hub.docker.com/r/egillax/shiny_debug_java

docker run -ti -p 3838:3838 egillax/shiny_debug_java

See app details at bottom.

I had this issue in the past on my laptop (ubuntu 22, openjdk 11). At the time I made a reprex and an issue here:

https://github.com/rstudio/DT/issues/1024

I don't think this is an issue with DT. This is something to do with how java code is accessed in reactive fields on shiny, seems to happen mostly on ubuntu. There is also a thread here about a similar issue:

https://community.rstudio.com/t/error-in-jcheck-java-exception-no-description-because-tostring-failed/161960/6

Today I have a newer ubuntu (23.10, openjdk 18), and this issue does not appear with the reprex. However the issue from rstudio community does appear.

App details ```R library(shiny) getValSummary <- function(){ sql <- "SELECT @column from @table" \# this is a function that uses java internally sql <- SqlRender::render(sql, column='my_column', table='my_table') valTable <- iris return(valTable) } ui <- fluidPage( titlePanel("Debug shiny Java error"), fluidRow( column(12, DT::DTOutput('table')) ) ) server <- function(input, output) { valTable <- reactive(getValSummary()) output$table <- DT::renderDT({ valTable() }) } # Run the application shinyApp(ui = ui, server = server) ```
egillax commented 7 months ago

I have a solution which solves this issue on my computer and in the docker container with the reprex. It's increasing the stack size with the java option "-Xss3m" or the lowest amount in megabytes that will make the error go away (3m worked for me). You can do this with an environment variable, for example to fix the issue in the docker container:

docker run -e _JAVA_OPTIONS='-Xss3m' -p 3838:3838 egillax/shiny_debug_java:latest

You can also put this in your user or project .Rprofile file:

options(java.parameters = "-Xss3m")

Before I couldn't run any shiny app using java code, or only really trivial example apps. Now everything seems to work that I've tried, including the reprex from the container and from the rstudio community post linked above as well as the plpViewer.

Credit goes to an IT guy in @jreps organization which suggested this fix.

PRijnbeek commented 7 months ago

I can confirm this works also for allowing it to run on ShinyApps.io and Posit Connect by adding options(java.parameters = "-Xss3m") as first line in Global.R

Very strange this is needed we are not doing deep stack work I think..