Bonjour,
Je suis débutant sur shiny et plus généralement sur R, j'aimerais avoir une aide sur un problème que je rencontre. En fait , je souhaite que mon code intéragisse avec mes radiobuttons mais je ne sais pas comment faire ce lien.
L'interface est celle que j'ai mis en PJ. Mes 3 bouttons sont int, conf et cat.
Lorsqu'il n y aucun bouton d'activer, la ligne ci-dessous est avec 000, lorsque que le boutton int est actif et les autres inactifs je veux 100. Avec cette même logique, lorsque les 3 sont actifs, je veux 111.
fullgrid <- genDefGrid(def, pl, pw, 000)
J'aimerais donc modifier fullgrid en fonction de ce que l'utilisateur choisi. Si vous avez des idées n'hesitez pas
Merci
Le code shiny complet :
library(shiny)
library(ggplot2)
library(gridExtra)
# Define UI
ui <- fluidPage(
# Application title
titlePanel("Defect map analysis"),
# Defect table selection
fluidRow(
column(2,
selectInput("prod", "Select a product:",
tb_prod[,"id"])
),
column(1, textOutput("lineid")),
column(1, textOutput("pdate")),
column(1, textOutput("ptime")),
column(1, textOutput("pfamily")),
column(1, textOutput("pac")),
column(1, textOutput("pcf")),
column(1, textOutput("pl")),
column(1, textOutput("pw")),
),
# First graph
fluidRow(
column(2,
wellPanel(
radioButtons("rbGraph1", "Graph:",
choiceNames = list("product", "defect"),
choiceValues = list("prod", "def"),
inline = T
),
radioButtons("rbDefect1", "Defect:",
choiceNames = list("point", "rect"),
choiceValues = list("point", "rect"),
inline = T
),
radioButtons("rbMain1", "Main:",
choiceNames = list("T+B", "T", "B"),
choiceValues = list("D", "T", "B"),
inline = T
),
checkboxGroupInput("cbWeight1", "Weight:",
choiceNames = list("int", "conf", "cat"),
choiceValues = list("int", "conf", "cat"),
inline = T
),
fluidRow(
column(6,
numericInput("numIn1", "Opacity:", 1, min = 1, width = 100)
),
column(6,
textInput("txtIn1", "Max value:", "display max", width = 100)
)
)
)
),
column(10,
plotOutput("prodPlot1")
)
),
# Second graph
fluidRow(
column(2,
wellPanel(
radioButtons("rbGraph2", "Graph:",
choiceNames = list("product", "defect"),
choiceValues = list("prod", "def"),
inline = T
),
radioButtons("rbDefect2", "Defect:",
choiceNames = list("point", "rect"),
choiceValues = list("point", "rect"),
inline = T
),
radioButtons("rbMain2", "Main:",
choiceNames = list("T+B", "T", "B"),
choiceValues = list("both", "top", "bot"),
inline = T
),
checkboxGroupInput("cbWeight2", "Weight:",
choiceNames = list("int", "conf", "cat"),
choiceValues = list("int", "conf", "cat"),
inline = T
),
fluidRow(
column(6,
numericInput("numIn2", "Opacity:", 1, min = 1, width = 100)
),
column(6,
textInput("txtIn2", "Max value:", "text here", width = 100)
)
)
)
),
column(10,
plotOutput("prodPlot2")
)
)
)
# Server logic
server <- function(input, output) {
output$lineid <- renderText({paste("Line: ", as.character(tb_prod[tb_prod$id==input$prod,"lineid"]))})
output$pdate <- renderText({paste("Date: ", as.character(tb_prod[tb_prod$id==input$prod,"pdate"]))})
output$ptime <- renderText({paste("Time: ", as.character(tb_prod[tb_prod$id==input$prod,"ptime"]))})
output$pfamily <- renderText({paste("Family: ", as.character(tb_prod[tb_prod$id==input$prod,"pfamily"]))})
output$pac <- renderText({paste("Aspect: ", as.character(tb_prod[tb_prod$id==input$prod,"pac"]))})
output$pcf <- renderText({paste("Conformity: ", as.character(tb_prod[tb_prod$id==input$prod,"pcf"]))})
output$pl <- renderText({paste("Length: ", as.character(tb_prod[tb_prod$id==input$prod,"pl"]))})
output$pw <- renderText({paste("Width: ", as.character(tb_prod[tb_prod$id==input$prod,"pw"]))})
output$prodPlot1 <- output$prodPlot2 <- renderPlot({
library(tidyverse)
source<- paste0("C:/Digitalization/Shiny/ProductMaps/InputFiles/", input$prod, ".def")
def <- read.csv(source)
pl <- as.numeric(tb_prod[tb_prod$id==input$prod,"pl"])
pw <- as.numeric(tb_prod[tb_prod$id==input$prod,"pw"])
deftop <- def %>% filter(side == "S")
defbot <- def %>% filter(side == "I")
fullgrid <- genDefGrid(def, pl, pw,000)
fullgridtop <- genDefGrid(deftop, pl, pw, 000)
fullgridbot <- genDefGrid(defbot, pl, pw, 000)
grid <- fullgrid %>% filter(z != 0)
gridtop <- fullgridtop %>% filter(z != 0)
gridbot <- fullgridbot %>% filter(z != 0)
# product map preparation
op <- 8
step <- 100
if (pl < 1000) { step <- 50 }
if (pl < 300) { step <- 20 }
# bi-side map without weigthing
mprod <- ggplot(grid) +
ggtitle("top+bot") +
aes(x, y) +
geom_point(shape=15, color = "blue", size = 2, alpha = (grid$z/op)) +
scale_x_continuous(name= "length (m)", breaks=seq(0, max(fullgrid[,"x"]), step)) +
scale_y_continuous(name= "width (mm)", breaks=seq(0, max(fullgrid[,"y"]), 100)) +
expand_limits(x = 0, y = 0) +
coord_cartesian(expand = FALSE) +
theme(plot.title = element_text(size=10, hjust = 0.5), axis.title.x = element_text(size=10), axis.text.x= element_text(angle=30, hjust=1), axis.title.y = element_text(size=10), axis.text.y= element_text(angle=30, hjust=1))
# top map without weigthing
mprodt <- ggplot(gridtop) +
ggtitle("top") +
aes(x, y) +
geom_point(shape=15, color = "blue", size = 2, alpha = (gridtop$z/op)) +
scale_x_continuous(name= "length (m)", breaks=seq(0, max(fullgridtop[,"x"]), step)) +
scale_y_continuous(name= "width (mm)", breaks=seq(0, max(fullgridtop[,"y"]), 100)) +
expand_limits(x = 0, y = 0) +
coord_cartesian(expand = FALSE) +
theme(plot.title = element_text(size=10, hjust = 0.5), axis.title.x = element_text(size=10), axis.text.x= element_text(angle=30, hjust=1), axis.title.y = element_text(size=10), axis.text.y= element_text(angle=30, hjust=1))
# top map without weigthing
mprodb <- ggplot(gridbot) +
ggtitle("bot") +
aes(x, y) +
geom_point(shape=15, color = "blue", size = 2, alpha = (gridbot$z/op)) +
scale_x_continuous(name= "length (m)", breaks=seq(0, max(fullgridbot[,"x"]), step)) +
scale_y_continuous(name= "width (mm)", breaks=seq(0, max(fullgridbot[,"y"]), 100)) +
expand_limits(x = 0, y = 0) +
coord_cartesian(expand = FALSE) +
theme(plot.title = element_text(size=10, hjust = 0.5), axis.title.x = element_text(size=10), axis.text.x= element_text(angle=30, hjust=1), axis.title.y = element_text(size=10), axis.text.y= element_text(angle=30, hjust=1))
grid.arrange(mprod, mprodt, mprodb, ncol = 2, layout_matrix = cbind(c(1,1), c(2,3)), widths=c(2,1))
})
}
# Complete app with UI and server components
shinyApp(ui, server)
Partager