Мне нужно сделать блестящее приложение, которое получает значение формулы, в которой пользователь вводит значения переменных через numericInput и selectInput. В первом случае замена проста, но я не могу найти, как выбрать параметр, выбранный в selectInput, преобразовать его, чтобы можно было включить его значение в формулу. Соотношение параметров выбора рабочего места отца составляет, например, «Работа» = 1; «Не работает» = 2. Код, который я сделал:
library(shiny)
ui<-navbarPage("REGRESION LOGISTICA",
tabPanel("RESULTADO",
sidebarLayout(sidebarPanel(
h5(helpText("Seleccione valores de las siguientes variables")),
tags$hr(),
# radioButtons(inputId = 'sep', label = 'Separator',
# choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ','),
selectInput("var",
label = "Seleccione Nivel de Estudio de la madre",
choices = c("Primaria Incompleta",
"Primaria Completa",
"Secundario Incompleto",
"Secundario Completo",
"Estudio Superior/Universitario Incompleto",
"Estudio Superior/ Universitario Completo"),
selected = "Secundario Completo"),
selectInput("var2",
label = "Seleccione Situacion laboral del padre",
choices = c("Trabaja", "No trabaja"),
selected = "Trabaja")),
mainPanel(#uiOutput("tb1")
numericInput("num_W", "Materias Regulares:", 0,min = 0, max = 15),
numericInput("num_l", "Edad:", 15,min = 15, max = 56),
h5(textOutput("Prueba")))
) ))
server<-function(input,output) {
#output$Prueba <- renderText({
# "La probabilidad de que el alumno NO continue sus estudios es:"
vals <- reactiveValues()
observe({
vals$W <- input$num_W
vals$L <- input$num_l
})
output$Prueba <- renderText({
paste("1.26624*Regulares+0.05381*Edad+EstMadreR+0.25075*SitLaboralPadre=",
1.26624*vals$W+0.05381*vals$L)
})
}
shinyApp(ui=ui,server=server)
Может ли кто-нибудь, пожалуйста, направить меня ???
Во-первых, чаи я предлагаю, чтобы ты определил два data,frame
, чтобы манипулировать выборами и "коэффициентами", например:
opciones_laborales <- data.frame(nombre = c("Trabaja", "No trabaja"),
coeficiente = c(1,2),
stringsAsFactors = FALSE
)
opciones_estudio <- data.frame(nombre = c("Primaria Incompleta", "Primaria Completa",
"Secundario Incompleto", "Secundario Completo",
"Estudio Superior/Universitario Incompleto",
"Estudio Superior/ Universitario Completo"),
coeficiente = c(1,2,3,4,5,6),
stringsAsFactors = FALSE
)
Потом, используй, что уже у тебя есть это и оно использует эти объекты, чтобы определять изогнутых. Например:
selectInput("var",
label = "Seleccione Nivel de Estudio de la madre",
choices = opciones_estudio$nombre,
selected = opciones_estudio$nombre[4])
Потом deber¦-схвати "наблюдать" двух изогнутых, чтобы захватывать действия пользователя с ними:
observe({
vals$W <- input$num_W
vals$L <- input$num_l
vals$Var <- input$var
vals$Var2 <- input$var2
})
И из-за último, construcci¦n текста, просто deberÃ: s видеть según отборный opci¦n, коэффициент, что ему соответствует
output$Prueba <- renderText({
o_estudio <- opciones_estudio$coeficiente[opciones_estudio$nombre == vals$Var]
o_laboral <- opciones_laborales$coeficiente[opciones_laborales$nombre == vals$Var2]
paste("1.26624*Regulares+0.05381*Edad+EstMadreR+0.25075*SitLaboralPadre=",
1.26624*vals$W+0.05381*vals$L+o_estudio+o_laboral*0.25075)
})
Конечный полный c¦digo:
library(shiny)
opciones_laborales <- data.frame(nombre = c("Trabaja", "No trabaja"),
coeficiente = c(1,2),
stringsAsFactors = FALSE
)
opciones_estudio <- data.frame(nombre = c("Primaria Incompleta", "Primaria Completa",
"Secundario Incompleto", "Secundario Completo",
"Estudio Superior/Universitario Incompleto",
"Estudio Superior/ Universitario Completo"),
coeficiente = c(1,2,3,4,5,6),
stringsAsFactors = FALSE
)
ui<-navbarPage("REGRESION LOGISTICA",
tabPanel("RESULTADO",
sidebarLayout(sidebarPanel(
h5(helpText("Seleccione valores de las siguientes variables")),
tags$hr(),
# radioButtons(inputId = 'sep', label = 'Separator',
# choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ','),
selectInput("var",
label = "Seleccione Nivel de Estudio de la madre",
choices = opciones_estudio$nombre,
selected = opciones_estudio$nombre[4]),
selectInput("var2",
label = "Seleccione Situacion laboral del padre",
choices = opciones_laborales$nombre,
selected = opciones_laborales$nombre[1])),
mainPanel(#uiOutput("tb1")
numericInput("num_W", "Materias Regulares:", 0,min = 0, max = 15),
numericInput("num_l", "Edad:", 15,min = 15, max = 56),
h5(textOutput("Prueba")))
) ))
server<-function(input,output) {
#output$Prueba <- renderText({
# "La probabilidad de que el alumno NO continue sus estudios es:"
vals <- reactiveValues()
observe({
vals$W <- input$num_W
vals$L <- input$num_l
vals$Var <- input$var
vals$Var2 <- input$var2
})
output$Prueba <- renderText({
o_estudio <- opciones_estudio$coeficiente[opciones_estudio$nombre == vals$Var]
o_laboral <- opciones_laborales$coeficiente[opciones_laborales$nombre == vals$Var2]
paste("1.26624*Regulares+0.05381*Edad+EstMadreR+0.25075*SitLaboralPadre=",
1.26624*vals$W+0.05381*vals$L+o_estudio+o_laboral*0.25075)
})
}
shinyApp(ui=ui,server=server)