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

Comments

@nutle
Copy link

@nutle 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
Copy link
Member

@hbaniecki 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

@hbaniecki hbaniecki commented Aug 6, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.