mohitji
mohitji

Reputation: 139

Assignment of variable using web app and performing operations on it

I am newbie to the r shiny and I am developing a web app that takes input as text and numeric. Next, the numeric value should be assigned to the declared text as a variable.

I have tried this

library(shiny)

ui<-fluidPage(    


  titlePanel("test"),

  numericInput("num", label = h3("Numeric input"), value = 1),

  hr(),
  fluidRow(column(3, verbatimTextOutput("value"))),

  textInput("text", label = h3("Text input"), value = "Enter text..."),

  hr(),
  fluidRow(column(3, verbatimTextOutput("value")))




)




server<-  function(input, output) {

  output$value <- renderPrint({ input$num })
  output$value <- renderPrint({ input$text })

}
shinyApp(ui = ui, server = server)

Now after this where is the value assigned? How can I extract the value of this assignment?

Upvotes: 0

Views: 71

Answers (1)

DSGym
DSGym

Reputation: 2867

Your errors: It is called renderText, not renderPrint. You can only assign one value to one output. However, if you want to output them togeher, you could do:

textoutput <- paste0(input$text, "," input$num)

Here you find a working example of your app. Next time, please format the text as code :-).

library(shiny)

ui<-fluidPage(

    titlePanel("test"),
    numericInput("num", label = h3("Numeric input"), value = 1),
    hr(), fluidRow(column(3, verbatimTextOutput("value"))),
    textInput("text", label = h3("Text input"), value = "Enter text..."),
    hr(), fluidRow(column(3, verbatimTextOutput("value1"),
                          verbatimTextOutput("value2")
                          ))

)

server<- function(input, output) {

    # value <- reactive({input$num})
    # valu2 <- reactive({input$text})

    output$value1 <- renderText({
        input$num
    })

    value <- reactive({input$num})

    output$value2 <- renderText({
        input$text
    })



} 

shinyApp(ui = ui, server = server)

Upvotes: 1

Related Questions