0

Basically, I want the user to provide a vector of values: X=1,2,3 and Y=2.3,4.5,6.7 in the shiny interface

and get a table like that:

X Y    
1 2.3  
2 4.5  
3 6.7  

However, I only get the values in a row:

X        Y    
1,2,3    2.3,4.5,6.7 

server

    library("shiny")
shinyServer(
  function(input,output,session){

    Data = reactive({
      if (input$submit > 0) {
        df <- data.frame(x=input$x,y=input$y)
        return(list(df=df))
      }
    })

    output$table <- renderTable({
      if (is.null(Data())) {return()}
      print(Data()$df)
    }, 'include.rownames' = FALSE
    , 'include.colnames' = TRUE
    , 'sanitize.text.function' = function(x){x}
    )

  })

ui

library("shiny")    
shinyUI(
  pageWithSidebar(
    headerPanel("textInput Demo")
    ,
    sidebarPanel(
      wellPanel(
        textInput('x', "enter X value here","")
        ,
        textInput('y', "enter Y value here","")
        ,
        actionButton("submit","Submit")
      )
    )
    ,
    mainPanel(uiOutput('table'))
  ))

Any ideas about how to solve this issue?

Thanks a LOT in advance,

1
  • You only get a string from textInput. You need to convert them to numbers. Commented Oct 9, 2016 at 15:41

1 Answer 1

1

textInput returns a string. So what you get is a single string "1,2,3" instead of three numbers. To convert the string to a vector of numbers

x = as.numeric(unlist(strsplit(input$x, ',')))
Sign up to request clarification or add additional context in comments.

Comments

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.