I am quite new to R shiny and so have not been able to figure out the solution from similar questions posted on this site. I am trying to read and use the input that a user provides to R shiny to generate an output.
I am trying to create a simple GUI where a user selects the name of a person (from a drop-down menu) and then enters his/her weight. If the height is above a certain threshold the output recommendation is "Gain Weight", else it is "Loose Weight".
Everything seems to be working fine, except for the following error from the Server.R file:
Error in `$.shinyoutput`(output, value_weight) :
Reading objects from shinyoutput object not allowed
How can I read and use the variable 'value_weight' in an if-then-else condition?
Main.R
library(shiny)
runApp()
Server.R
function(input, output) {
# You can access the value of the widget with input$select, e.g.
output$value_name <- renderPrint({ input$select })
output$value_weight <- renderPrint({ input$num })
if(output$value_weight > 150)
{
output$value_recommendation <- "Loose Weight"
}
else{
output$value_recommendation <- "Gain Weight"
}
}
UI.R
names_list <- list("Adam", "Jenna","Peter")
fluidPage(
selectInput("select", label = h3("Select Name"), choices = names_list, selected = 1),
hr(),
fluidRow(column(3, verbatimTextOutput("value_name"))),
numericInput("num", label = h3("Enter Weight"), value = 0),
hr(),
fluidRow(column(3, verbatimTextOutput("value_weight"))),
hr(),
fluidRow(column(3, verbatimTextOutput("value_recommendation")))
)