mages / googleVis

Interface between R and the Google Chart Tools
https://mages.github.io/googleVis/
358 stars 156 forks source link

Org Chart under shiny 0.11.1 and shinydashboard #13

Open alainva opened 9 years ago

alainva commented 9 years ago

Hi,

I use googleVis_0.4.7 (in other Org Chart) to publish the taxonomy of risk solvency2 (about it thank you for the latest version of ChainLadder). One of the feature is to display the correlation matrix if you click on a block of risk diversification (Diversification Market Risk, No Risk Life, ...)

Using shiny 0.11.1 under shinybootstrap2 this is not a problem, but I migrated my application to shinydashboard_0.2.3 and I can not see the matrix despite the capture of diversification selected block (see the alert function).

Below is the functions used (recovering the block name in shiny input with $ selected)

Do you have a solution to this problem ?

A big thank you for your help.

Alain

output$S2Taxo <- renderGvis({

jscode <- "var sel = chart.getSelection();
var c = sel[0].row;
var text = data.getValue(c, 0);               
alert(text);
$('input#selected').val(text);
$('input#selected').trigger('change');"   

if (input$Taxo==FALSE){

SII_Taxo_S<-dplyr::filter(dbTaxoDyn(), Origin=='SCR')
gvisOrgChart(SII_Taxo_S, idvar = "KeyRisk", parentvar = "KeyParentLevel2", tipvar="Value",  options=list(gvis.listener.jscode=jscode,width=300, height=600,allowHtml=TRUE, size='large', allowCollapse=TRUE))
}
else if (input$Taxo==TRUE){
gvisOrgChart(dbTaxoDyn(), idvar = "KeyRisk", parentvar = "KeyParent", tipvar="Value",  options=list(gvis.listener.jscode=jscode,width=300, height=600,allowHtml=TRUE, size='large', allowCollapse=TRUE))
}

})

  dataTaxo<-reactive({

Search Risk Nr 1

    vvv<-readTaxoMulti(input$selected)
    #cat(vvv$FieldName)
    return(vvv)
})

observe({ if (is.null(input$selected))
return()
isolate({

  v<-readTaxoMulti(input$selected)  

  pub<-paste(v$FieldName," :  ",v$FieldValue)

})  

})

#Correlation Matrix  #
######################

CorrelMatrix<-reactive ({
# Error message 
validate(
  need(dataTaxo()$FieldName != "", "Please click on a Diversification block to see the correlation matrix")
)

SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="NoCorr",]
if(dataTaxo()$FieldName=="DiversificationBSCR")
{SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_BSCR",]}
else if (dataTaxo()$FieldName=="DiversificationNONLIFE")
{SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_nonlife",]}
else if (dataTaxo()$FieldName=="Diversification LIFE")
{SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_Life",]}
else if (dataTaxo()$FieldName=="DiversificationMARKET")
{SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_market_down",]}
else if (dataTaxo()$FieldName=="Diversification HEALTH")
{SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_health",]}
else if (is.na(dataTaxo()$FieldName)) 
{SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="NoCorr",]}

dimMat <- dim(SII_COR_SEL)[1]^0.5
aaa <- melt(SII_COR_SEL)
bbb <- as.data.frame(cast(aaa, Item1 ~ Item2))
cat(bbb)
return(bbb)
})

output$correlaM <- renderTable({

CorrelMatrix()
})

sessionInfo() R version 3.1.2 (2014-10-31) Platform: i386-w64-mingw32/i386 (32-bit)

locale: [1] LC_COLLATE=Dutch_Belgium.1252 LC_CTYPE=Dutch_Belgium.1252
[3] LC_MONETARY=Dutch_Belgium.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Belgium.1252

attached base packages: [1] stats graphics grDevices utils datasets methods
[7] base

other attached packages: [1] shinydashboard_0.2.3 geoR_1.7-4
[3] sp_1.0-9 fOptions_3010.83
[5] fBasics_3010.86 MASS_7.3-35
[7] timeSeries_3010.97 timeDate_3010.98
[9] quantmod_0.4-0 TTR_0.22-0
[11] Defaults_1.1-1 tseries_0.10-32
[13] xts_0.9-7 ggplot2_0.9.3.1
[15] PerformanceAnalytics_1.1.0 dygraphs_0.3.3
[17] shinyBS_0.25 shinysky_0.1.2
[19] lattice_0.20-29 scales_0.2.4
[21] RColorBrewer_1.0-5 leaflet_1.0
[23] hwriter_1.3 data.table_1.8.8
[25] rHighcharts_1.0 RJSONIO_1.0-3
[27] actuar_1.1-6 shiny_0.11.1
[29] ChainLadder_0.2.0 statmod_1.4.17
[31] systemfit_1.1-14 lmtest_0.9-31
[33] zoo_1.7-11 car_2.0-21
[35] Matrix_1.1-4 stringr_0.6.2
[37] googleVis_0.4.7 dplyr_0.4.0
[39] reshape_0.8.4 plyr_1.8.1
[41] RODBC_1.3-6 JavaGD_0.6-1
[43] codetools_0.2-9

loaded via a namespace (and not attached): [1] assertthat_0.1 cluster_1.15.3 colorspace_1.2-4
[4] DBI_0.3.1 digest_0.6.4 grid_3.1.2
[7] gtable_0.1.2 Hmisc_3.12-2 htmltools_0.2.6
[10] htmlwidgets_0.3.2 httpuv_1.3.2 lme4_0.999999-2
[13] magrittr_1.5 mime_0.2 munsell_0.4.2
[16] nlme_3.1-118 nnet_7.3-8 parallel_3.1.2
[19] proto_0.3-10 quadprog_1.5-5 R6_2.0
[22] RandomFields_2.0.66 Rcpp_0.11.3 reshape2_1.4
[25] rpart_4.1-8 sandwich_2.2-10 SparseM_1.05
[28] splancs_2.01-32 stabledist_0.6-6 stats4_3.1.2
[31] tools_3.1.2 tweedie_2.1.7 xtable_1.7-4
[34] yaml_2.1.13

ncdingari commented 9 years ago

I also had the same problem. shinydashboard is not rendering OrgChart and SankeCharts from googleVis. I think the problem is with shinydashboard.

Sent from my iPhone

On Mar 27, 2015, at 5:16 AM, alainva notifications@github.com wrote:

Hi,

I use googleVis_0.4.7 (in other Org Chart) to publish the taxonomy of risk solvency2 (about it thank you for the latest version of ChainLadder). One of the feature is to display the correlation matrix if you click on a block of risk diversification (Diversification Market Risk, No Risk Life, ...)

Using shiny 0.11.1 under shinybootstrap2 this is not a problem, but I migrated my application to shinydashboard_0.2.3 and I can not see the matrix despite the capture of diversification selected block (see the alert function).

Below is the functions used (recovering the block name in shiny input with $ selected)

Do you have a solution to this problem ?

A big thank you for your help.

Alain

output$S2Taxo <- renderGvis({

jscode <- "var sel = chart.getSelection(); var c = sel[0].row; var text = data.getValue(c, 0);
alert(text); $('input#selected').val(text); $('input#selected').trigger('change');"

if (input$Taxo==FALSE){

SII_Taxo_S<-dplyr::filter(dbTaxoDyn(), Origin=='SCR') gvisOrgChart(SII_Taxo_S, idvar = "KeyRisk", parentvar = "KeyParentLevel2", tipvar="Value", options=list(gvis.listener.jscode=jscode,width=300, height=600,allowHtml=TRUE, size='large', allowCollapse=TRUE)) } else if (input$Taxo==TRUE){ gvisOrgChart(dbTaxoDyn(), idvar = "KeyRisk", parentvar = "KeyParent", tipvar="Value", options=list(gvis.listener.jscode=jscode,width=300, height=600,allowHtml=TRUE, size='large', allowCollapse=TRUE)) }

})   dataTaxo<-reactive({

Search Risk Nr 1

vvv<-readTaxoMulti(input$selected)

cat(vvv$FieldName)

return(vvv)

}) observe({ if (is.null(input$selected))

return()

isolate({

v<-readTaxoMulti(input$selected)

pub<-paste(v$FieldName," : ",v$FieldValue)

})
})

######################

Correlation Matrix

######################

CorrelMatrix<-reactive ({

Error message

validate( need(dataTaxo()$FieldName != "", "Please click on a Diversification block to see the correlation matrix") )

SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="NoCorr",] if(dataTaxo()$FieldName=="DiversificationBSCR") {SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_BSCR",]} else if (dataTaxo()$FieldName=="DiversificationNONLIFE") {SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_nonlife",]} else if (dataTaxo()$FieldName=="Diversification LIFE") {SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_Life",]} else if (dataTaxo()$FieldName=="DiversificationMARKET") {SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_market_down",]} else if (dataTaxo()$FieldName=="Diversification HEALTH") {SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="Agg_matrix_health",]} else if (is.na(dataTaxo()$FieldName)) {SII_COR_SEL<-SII_COR[SII_COR[,"Matrix"]=="NoCorr",]}

dimMat <- dim(SII_COR_SEL)[1]^0.5 aaa <- melt(SII_COR_SEL) bbb <- as.data.frame(cast(aaa, Item1 ~ Item2)) cat(bbb) return(bbb) })  

output$correlaM <- renderTable({

CorrelMatrix() }) sessionInfo() R version 3.1.2 (2014-10-31) Platform: i386-w64-mingw32/i386 (32-bit)

locale: [1] LC_COLLATE=Dutch_Belgium.1252 LC_CTYPE=Dutch_Belgium.1252

[3] LC_MONETARY=Dutch_Belgium.1252 LC_NUMERIC=C

[5] LC_TIME=Dutch_Belgium.1252

attached base packages: [1] stats graphics grDevices utils datasets methods

[7] base

other attached packages: [1] shinydashboard_0.2.3 geoR_1.7-4

[3] sp_1.0-9 fOptions_3010.83

[5] fBasics_3010.86 MASS_7.3-35

[7] timeSeries_3010.97 timeDate_3010.98

[9] quantmod_0.4-0 TTR_0.22-0

[11] Defaults_1.1-1 tseries_0.10-32

[13] xts_0.9-7 ggplot2_0.9.3.1

[15] PerformanceAnalytics_1.1.0 dygraphs_0.3.3

[17] shinyBS_0.25 shinysky_0.1.2

[19] lattice_0.20-29 scales_0.2.4

[21] RColorBrewer_1.0-5 leaflet_1.0

[23] hwriter_1.3 data.table_1.8.8

[25] rHighcharts_1.0 RJSONIO_1.0-3

[27] actuar_1.1-6 shiny_0.11.1

[29] ChainLadder_0.2.0 statmod_1.4.17

[31] systemfit_1.1-14 lmtest_0.9-31

[33] zoo_1.7-11 car_2.0-21

[35] Matrix_1.1-4 stringr_0.6.2

[37] googleVis_0.4.7 dplyr_0.4.0

[39] reshape_0.8.4 plyr_1.8.1

[41] RODBC_1.3-6 JavaGD_0.6-1

[43] codetools_0.2-9

loaded via a namespace (and not attached): [1] assertthat_0.1 cluster_1.15.3 colorspace_1.2-4

[4] DBI_0.3.1 digest_0.6.4 grid_3.1.2

[7] gtable_0.1.2 Hmisc_3.12-2 htmltools_0.2.6

[10] htmlwidgets_0.3.2 httpuv_1.3.2 lme4_0.999999-2

[13] magrittr_1.5 mime_0.2 munsell_0.4.2

[16] nlme_3.1-118 nnet_7.3-8 parallel_3.1.2

[19] proto_0.3-10 quadprog_1.5-5 R6_2.0

[22] RandomFields_2.0.66 Rcpp_0.11.3 reshape2_1.4

[25] rpart_4.1-8 sandwich_2.2-10 SparseM_1.05

[28] splancs_2.01-32 stabledist_0.6-6 stats4_3.1.2

[31] tools_3.1.2 tweedie_2.1.7 xtable_1.7-4

[34] yaml_2.1.13

— Reply to this email directly or view it on GitHub.

mages commented 9 years ago

Hi Alain, Can you please provide a minimal reproducible example in R that I can run on my side? Have you tried updating googleVis to the current version?

Thanks

Markus

alainva commented 9 years ago

Hi Markus

Thank you for your reply Attached is an example (a version in shinydashboard and the other shinyboostrap2) the goal is to get the name of the block clicked by the user

thank you for your help

Alain

On Fri, Mar 27, 2015 at 8:53 PM, Markus Gesmann notifications@github.com wrote:

Hi Alain, Can you please provide a minimal example in R that I can run on my side? Have you tried updating googleVis to the current version?

Thanks

Markus

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/13#issuecomment-87070874.

Alain Vanlanduyt 0474/900.446

mages commented 9 years ago

Hi Alain,

I can't see the attached file. Perhaps you can add a link instead.

Thanks

Markus

alainva commented 9 years ago

Hi Markus

For the version under bootstrap2 the code was :

server.r

shinybootstrap2::withBootstrap2({

server <- function(input, output,session) {

output$Test1 <- renderGvis({

jscode <- "var sel = chart.getSelection();

var c = sel[0].row;

var text = data.getValue(c, 0);

alert(text);

$('input#selected').val(text);

$('input#selected').trigger('change');"

Org <- gvisOrgChart(Regions, options=list(gvis.listener.jscode=jscode,width=300, height=600,allowHtml=TRUE, size='large', allowCollapse=TRUE))

})

output$BlocSelect <- renderText({

paste("Bloc : ", dataT())

})

observe({

if (is.null(input$selected))

return()

isolate({

v<-(input$selected)

pub<-paste(" : ",v)

})

})

dataT<-reactive({

Search Risk Nr 1

vvv<-(input$selected)

cat(vvv)

return(vvv)

})

}

})

ui.R

shinybootstrap2::withBootstrap2({

shinyUI(bootstrapPage(

shinyUI(navbarPage(title="TestOrgChart",id="test",

tabPanel("Tab1",

div(class="span4", strong(textOutput("BlocSelect"))),

div(class="row",div(class="span12",chartOutput("Test1")))

)

))

))

}) and with shinydashboard

server.r (the same without shinybootstrap2)

server <- function(input, output,session) {

output$Test1 <- renderGvis({

jscode <- "var sel = chart.getSelection();

var c = sel[0].row;

var text = data.getValue(c, 0);

alert(text);

$('input#selected').val(text);

$('input#selected').trigger('change');"

Org <- gvisOrgChart(Regions, options=list(gvis.listener.jscode=jscode,width=300, height=600,allowHtml=TRUE, size='large', allowCollapse=TRUE))

})

output$BlocSelect <- renderText({

paste("Bloc : ", dataT())

})

observe({

if (is.null(input$selected))

return()

isolate({

v<-(input$selected)

pub<-paste(" : ",v)

})

})

dataT<-reactive({

Search Risk Nr 1

vvv<-(input$selected)

cat(vvv$FieldName)

return(vvv)

})

}

ui.r

library(shinydashboard)

ui <- dashboardPage(

dashboardHeader(title = "Test OrgChart"),

dashboardSidebar(

menuItem("Test", tabName = "TestOrg")

),

dashboardBody(

tabItems(

tabItem(tabName = "TestOrg",

box(title = "Input", status = "warning", solidHeader = TRUE,width = NULL,textOutput("BlocSelect")),

box(title = "OrgChart", status = "primary", solidHeader = TRUE,width = NULL,chartOutput("Test1"))

)

)

)

)

Thanks for your help

Alain

On Mon, Mar 30, 2015 at 10:45 PM, Markus Gesmann notifications@github.com wrote:

Hi Alain,

I can't see the attached file. Perhaps you can add a link instead.

Thanks

Markus

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/13#issuecomment-87826322.

Alain Vanlanduyt 0474/900.446

mages commented 9 years ago

Alain,

I have added missing library calls to your code and I believe it works. You find the code here: https://gist.github.com/2cfd64245c5e1243ca83.git

Here is screen shot (session info below): shinydashboard

sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.2 (Yosemite)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shinybootstrap2_0.2.1 googleVis_0.5.8       rHighcharts_1.0       RJSONIO_1.3-0        
[5] shinydashboard_0.3.0  shiny_0.11.1         

loaded via a namespace (and not attached):
[1] digest_0.6.8    htmltools_0.2.6 httpuv_1.3.2    jsonlite_0.9.14 mime_0.2       
[6] R6_2.0.1        Rcpp_0.11.5     tools_3.1.3     xtable_1.7-4
alainva commented 9 years ago

Hi Markus

Thank you for your answer.

I got the same result but the goal is to retrieve the name of the block clicked by the user and to publish it in the input box via textOutput function ("BlocSelect") of ui.R and via recative function dataT () of server.R

Do you have this?

Thank you in advance

Alain

On Tue, Mar 31, 2015 at 10:22 PM, Markus Gesmann notifications@github.com wrote:

Alain,

I have added missing library calls to your code and I believe it works. You find the code here: https://gist.github.com/2cfd64245c5e1243ca83.git

Here is screen shot: [image: shinydashboard] https://cloud.githubusercontent.com/assets/1146581/6928416/ceabb62a-d7eb-11e4-988d-20c1bf6c86df.png

sessionInfo() R version 3.1.3 (2015-03-09) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.2 (Yosemite)

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] shinybootstrap2_0.2.1 googleVis_0.5.8 rHighcharts_1.0 RJSONIO_1.3-0 [5] shinydashboard_0.3.0 shiny_0.11.1

loaded via a namespace (and not attached): [1] digest_0.6.8 htmltools_0.2.6 httpuv_1.3.2 jsonlite_0.9.14 mime_0.2 [6] R6_2.0.1 Rcpp_0.11.5 tools_3.1.3 xtable_1.7-4

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/13#issuecomment-88232764.

Alain Vanlanduyt 0474/900.446

mages commented 9 years ago

Hi Alain,

Oh, now I understand what you would like to achieve. Unfortunately I don’t think that I can help you with this.

Regards

Markus

On 1 Apr 2015, at 20:10, alainva notifications@github.com wrote:

Hi Markus

Thank you for your answer.

I got the same result but the goal is to retrieve the name of the block clicked by the user and to publish it in the input box via textOutput function ("BlocSelect") of ui.R and via recative function dataT () of server.R

Do you have this?

Thank you in advance

Alain

On Tue, Mar 31, 2015 at 10:22 PM, Markus Gesmann notifications@github.com wrote:

Alain,

I have added missing library calls to your code and I believe it works. You find the code here: https://gist.github.com/2cfd64245c5e1243ca83.git

Here is screen shot: [image: shinydashboard] https://cloud.githubusercontent.com/assets/1146581/6928416/ceabb62a-d7eb-11e4-988d-20c1bf6c86df.png

sessionInfo() R version 3.1.3 (2015-03-09) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.2 (Yosemite)

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] shinybootstrap2_0.2.1 googleVis_0.5.8 rHighcharts_1.0 RJSONIO_1.3-0 [5] shinydashboard_0.3.0 shiny_0.11.1

loaded via a namespace (and not attached): [1] digest_0.6.8 htmltools_0.2.6 httpuv_1.3.2 jsonlite_0.9.14 mime_0.2 [6] R6_2.0.1 Rcpp_0.11.5 tools_3.1.3 xtable_1.7-4

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/13#issuecomment-88232764.

Alain Vanlanduyt 0474/900.446 — Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/13#issuecomment-88597832.