2016-06-16 6 views
0

테이블을 쿼리 할 수있는 Talend DI를 사용하여 RESTful API를 만든 PostgreSQL 데이터베이스가 있습니다.
내 질문은 내 Api 's를 Shiny로 호출하고 데이터를 표시하는 방법입니다.SHINY에 HTTP GET 데이터 표시

[{"medical_consultations":{"medical_consultation":[{"id":"1640087","id_consultation":"GFAPAAPA P 834406012009","consultation_date":"07-01-2009","id_center":"APA"},{"id":"1640088","id_consultation":"GFAPAAPA P1079007012010","consultation_date":"08-01-2010","id_center":"APA"},{"id":"1640089","id_consultation":"GFAPAAPA P1098811052007","consultation_date":"12-05-2007","id_center":"APA"}]}}] 

시 : HTTP GET 응답의

예를 들어 나는 아무 문제가 내 데이터베이스에 직접 연결하는 샤이니의 'RPostgreSQL'패키지를 사용하여 그 일을하지 않은하지만 난 빛나는에서 분리하는 것을 선호하고는 것 "에 텍스트 상자에 텍스트를 설정 예를 들어

require(shiny) 
require(httr) 

url <- "http://httpbin.org/get?" 

ui <- fluidPage(
    sidebarLayout(
    sidebarPanel(
     textInput('GETargs',"GET string"), 
     actionButton('sendGET','Send') 
    ), 
    mainPanel(
     verbatimTextOutput('GETresponse'), 
     dataTableOutput('table1') 
    ) 
) 
) 

server <- function(input, output, session) { 
    observeEvent(input$sendGET, { 
    getargs <- input$GETargs 

    if(is.null(input$GETargs)) getargs <- "" 

    res    <- GET(sprintf("%s%s",url, getargs)) 
    output$GETresponse <- renderPrint(content(res)) 

    output$table1 <- renderDataTable(as.data.frame(content(res)$args)) 
    }) 
} 

runApp(shinyApp(ui,server)) 

: 당신이 API가있는 경우 내 웹 서비스를 사용하여

답변

1

모든 설정은 당신이 뭔가를 할 수 있습니다 param1 = value1 & param2 = value2 "는 선택한 URL에 GET 요청을 보냅니다. 이것은 당신이 이것을 구현하고자하는 방식이 아닐지도 모르지만 이것이 어떻게 할 수 있는지에 대한 약간의 아이디어를 줄 수도 있습니다. 내가 입력하여 인스턴스 액세스 "PARAM1"의 값에 대해 내가 할 수있는 예제 쿼리 고통을 사용하는 경우

:

content(res)$args$param1 
+0

은 꽤 좋은 근무하지만 테이블로 아니므로 그것은 어떻게 데이터를 렌더링 나는 그것을 테이블에 넣었다? –

+0

테이블을 렌더링하려면 data.frame이나 매트릭스를 만들어야하고, '? renderDataTable' 또는'? renderTable'을보십시오. 내 대답을 업데이트하여 GET 매개 변수를 테이블에 반환했습니다. –