Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running model studio in a shiny app #77

Closed
nutle opened this issue Jul 28, 2020 · 2 comments
Closed

Running model studio in a shiny app #77

nutle opened this issue Jul 28, 2020 · 2 comments
Labels
feature 💡 New feature or enhancement request question ❔ Further information is requested
Milestone

Comments

@nutle
Copy link

nutle commented Jul 28, 2020

I would like to include the model output inside an existing shiny app (or as a standalone app). Is there any existing code or wrappers for this?

@hbaniecki hbaniecki added feature 💡 New feature or enhancement request question ❔ Further information is requested labels Jul 28, 2020
@hbaniecki
Copy link
Member

hbaniecki commented Jul 28, 2020

I think it would be a great feature to support modelStudio in Shiny. I added a widget_id argument to the modelStudio() function on the ms-shiny branch. I'm not a shiny expert but it should allow for modelStudio rendering using the r2d3 package (modelStudio is a r2d3 class object, see https://rstudio.github.io/r2d3/articles/shiny.html).

You can install the new version using

install.packages('devtools')
devtools::install_github('ModelOriented/modelStudio', ref='ms-shiny')

and try it out - feedback appreciated, as I can expand this feature further.

Consider the following example:

library(shiny)
library(r2d3)


ui <- fluidPage(
  textInput("text", h3("Text input"), 
            value = "Enter text..."),
  uiOutput('dashboard')
)

server <- function(input, output) {
  #:# id of div where modelStudio will appear
  WIDGET_ID = 'MODELSTUDIO'
  
  #:# create modelStudio 
  library(modelStudio)
  library(DALEX)
  model <- glm(survived ~., data = titanic_imputed, family = "binomial")
  explainer <- explain(model,
                       data = titanic_imputed,
                       y = titanic_imputed$survived,
                       label = "Titanic GLM",
                       verbose = FALSE)
  ms <- modelStudio(explainer,
                    widget_id = WIDGET_ID,  #:# use the widget_id 
                    show_info = FALSE)    
  ms$elementId <- NULL                      #:# remove elementId to stop the warning

  #:# basic render d3 output
  output[[WIDGET_ID]] <- renderD3({
    ms
  })
  
  #:# use render ui to set proper width and height
  output$dashboard <- renderUI({
    d3Output(WIDGET_ID, width=ms$width, height=ms$height)
  })
}

shinyApp(ui = ui, server = server)

@hbaniecki
Copy link
Member

The example is now added to the vignette https://modelstudio.drwhy.ai/articles/ms-perks-features.html#shiny-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 💡 New feature or enhancement request question ❔ Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants