0

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?

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you :) Now what to do if i have to use the entered numeric value as input for another operation. For Example, say value 2 is entered as input..now after entering, i want to display the square of 2 is 4.
input$num * 2 or if is has to be text: paste0("The square of ", input$num", " is ", input$num * 2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.