I have 6 variables for a mixture design of experiment and fitted a lm model with interactions. Trying to use 'ModelPlot' function for contour plot in shiny and let user choose which 3 variables to be in plot and the other 3 to hold fixed values in slice argument, however it does not work and giving me errors. Can someone help with it? Or is this function not shiny-friendly, what would be a better way to do this?
library(shiny)
library(dplyr)
library(mixexp)
load(mix_model)
var_choices = c("f1", "f2", "f3", "f4", "f5", "f6")
Define UI for application that draws a contour plot
ui <- fluidPage(
titlePanel("Design of Experiment Plot"),
sidebarLayout(
sidebarPanel(
h3("Select variables for contour plot"),
fluidRow(
column(6,
selectInput("in_f1",
"assign a variable as f1:",
choices = var_choices,
selected = "f1")),
column(6,
sliderInput("range_f1", "range for f1:",
min = 0, max = 0.5, value = c(0, 5),
dragRange = TRUE, sep = ""))),
fluidRow(
column(6,
selectInput("in_f2",
"assign a variable as f2:",
choices = var_choices,
selected = "f2")),
column(6,
sliderInput("range_f2", "range for f2:",
min = 0, max = 0.5, value = c(0, 5),
dragRange = TRUE, sep = ""))),
fluidRow(
column(6,
selectInput("in_f3",
"assign a variable as f3:",
choices = var_choices,
selected = "f3")),
column(6,
sliderInput("range_f3", "range for f3:",
min = 0, max = 0.5, value = c(0, 5),
dragRange = TRUE, sep = ""))),
fluidRow(
column(6,
selectInput("in_f4",
"assign a variable as f4:",
choices = var_choices,
selected = "f4")),
column(6,
sliderInput("val_f4",
"fix value for f4:",
min = 0, max = 0.5, value = 0, step = 0.01))),
fluidRow(
column(6,
selectInput("in_f5",
"assign a variable as f5:",
choices = var_choices,
selected = "f5")),
column(6,
sliderInput("val_f5",
"fix value for f5:",
min = 0, max = 0.5, value = 0, step = 0.01))),
fluidRow(
column(6,
selectInput("in_f6",
"assign a variable as f6:",
choices = var_choices,
selected = "f6")),
column(6,
sliderInput("val_f6",
"fix value for f6:",
min = 0, max = 0.5, value = 0, step = 0.01)))
),
mainPanel(
plotOutput("contourplot")
)
)
)
Define server logic
server <- function(input, output) {
output$contourplot <- renderPlot ({
mix_plot <- ModelPlot (
model = mix_model,
dimensions = list(x1 = input$in_f1, x2 = input$in_f2, x3 = input$in_f3),
slice = list(mix.vars = c(input$in_f4 = input$val_f4, input$in_f5 = input$val_f5, input$in_f6 = input$val_f6)),
lims=c(input$range_f1,input$range_f2,input$range_f3),
main = paste("Contour Plot"),
constraints = TRUE, contour = TRUE, fill = TRUE,
axislabs = c(input$in_f1, input$in_f2, input$in_f3),
cornerlabs = c("X1", "X2", "X3"),
pseudo = FALSE
)
})
}
shinyApp(ui = ui, server = server)