2016-10-09 51 views
0

基本上,我希望用戶提供一個值向量:X = 1,2,3和Y = 2.3,4.5,6.7在閃亮的界面中從閃亮輸入創建多行數據幀

並得到這樣的一個表:

X Y  
1 2.3 
2 4.5 
3 6.7 

不過,我只得到了價值一排:

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

服務器

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')) 
)) 

如何解決這個問題的任何想法?

在此先感謝了很多,

+0

您只從'textInput'獲得一個字符串。你需要將它們轉換爲數字。 –

回答

1

textInput返回一個字符串。所以你得到的是一個字符串"1,2,3"而不是三個數字。將字符串轉換爲數字向量

x = as.numeric(unlist(strsplit(input$x, ',')))