Need Help with server.R input for R shiny

Hi Everyone! Need a favour

I have coded the ui.R page with the following
library(shiny)
install.packages("shiny")

library(shiny)
library(shinythemes)
library(shinydashboard)
library(ggplot2)
library(mlutils)
install.packages("mlutils")
install.packages("shinythemes")
install.packages("shinydashboard")
install.packages("shinyWidgets")
library(shinyWidgets)

ui <- fluidPage(

sliderInput(inputId = "num",
label = "Age in month",
value = 25, min = 1, max = 1500),
numericInput(inputId = "sys",
label = "Height in cm",
value = 160, min = 1, max = 240),

numericInput(inputId = "dia",
label = "Weight in Kg",
value = 90, min = 1, max = 300),

selectInput("Gender", "Gender", c("Man", "Woman")),

numericInput(inputId = "num",
label = "Systolic blood pressure",
value = 90, min = 1, max = 300),
numericInput(inputId = "num",
label = "Diastolic blood pressure",
value = 90, min = 1, max = 300),

selectInput("Cholesterol", "Cholesterol", c("Normal", "Above Normal", "Much above Normal")),

selectInput("Glucose", "Glucose", c("Normal", "Above Normal", "Much above Normal")),

radioGroupButtons("Alcohol consumption", "Alcohol consumption", c("Yes", "Not at all")),
radioGroupButtons("Lifestyle", "Lifestyle", c("Active", "Not Active")),

tags$h2("Risk of Cardiovascular Disease"),
setBackgroundImage(
src = "https://cdn.pixabay.com/photo/2018/06/27/08/12/heart-3501018_1280.jpg"),
textOutput("selected_var")
)

server <- function(input, output) {}
shinyApp(server = server, ui = ui)

I need to build the output, into a regression equation, and compute the final result as y=mx1+ nx2+ox3.... How do I input the categorical variables like Gender, "Male" which was assigned a dummy variable "1", say!

Can anyone please guide me on how to build the server.R codes

The most charitable interpretation I can give is to assume that you mean to have a particular dataset with particular regression having been conducted upon it and your intention now is to , through the use of the shiny input controllers you listed allow a user to construct an arbitrary data observation , so that you can score it for them.
If this is the case then you should provide at least the regression result that you have.

P.s. your code does strange things with the libraries like installing them to your system after trying to attach them. This is bad practice. The simple approach is to install them for yourself once on the console say, and then any app script you write would only attach them each time it's run. Or else add a step which tests if a library is installed or not, and dynamically call installer only if needed.

Hey thanks! I will try and do that, I already have an equation, just need a logic to fit in the "Coefficient*(variable)" component into the equation and print the result. The data that is numerically captured is ok, it would so kind of you to suggest how to go about the categorical variables (eg: Gender> male).

Can we use these ?
h <- as.numeric(input$one),
i <- as.numeric(input$two),
j <- as.numeric(input$Gender_Man),
k <- as.numeric(input$Gender_Woman), and then build the equation and print the result

Use this approach...

j <- ifelse(input$Gender == 'Man',1,0)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.