I am trying to make an app using R shiny (see below).
If I select 'Item1', I want the server-side to select the number corresponding to 'Item1' which is 10. Then multiply this value (10) with another number (say 5) and return the output as 'value'. How do I write the server-side code?
Thank you so much.
P.S.: I am a beginner in R
df <- data.frame(item = c('Item1', 'Item2'),
value = c(10, 20))
ui <- fluidPage(sidebarPanel(selectInput(inputId = 'name',
label = 'select item:',
df$item)),
textOutput('value') )
CodePudding user response:
You can index into the value column using the name value. For example
server <- function(input, output, session) {
output$value <- renderText(df$value[df$item == input$name])
}