2017-11-07 2 views
0

UI에서 SelectInput objet의 목록을 느낄 수 있도록 한 열의 데이터 프레임 행을 읽으려고했습니다. Shiny UI와 서버 사이의 전역 또는 로컬 참조에 문제가 있습니다. 형식은 하나의 열 (STEP_NAME) 내 DF Ref_comp 여기 selectInput 목록데이터 프레임 열의 SelectInput이있는 Shiny

수입 항목에 적합한 지 모르는 : 여기

! STEP_NAME ! 
----------------- 
    L1_2_3_LR 
    C46-C77-OTHERS 
    R4 
    R10 
    C56 
    Q4 
    L4 

내 UI.R

shinyUI(pageWithSidebar(

    headerPanel("My header Text"), 
    sidebarPanel( 
    radioButtons("test", "Select a DataBase", 
         c("test1"="test1", 
         "test2"="test2")), 
      textInput("card", "Enter the code card", "CARD.EX"), 
      textInput("comp", "Enter the ref comp", "R3"), 
      ######## Here what I tried to do ######## 
      selectInput("comp_sel","Component", choices= 
      as.character(unique(unlist(Ref_comp$STEP_NAME)))), 
      ########################################## 
      downloadButton("plot_export", "Save PDF") 
         ), 

mainPanel(
    #h4("Text2"), 
     library(plotly), 
     plotlyOutput("plot")) 


    )) 
여기

shinyServer(function(input,output){ 

output$plot <- renderPlotly({ 

con <- odbcConnect(con, uid="xxx") 

##### Here the SQL Query to have my items ###################### 
sql_ref = paste("select DISTINCT ...") # My SQL query on distant server 
###### Output in DF Ref_comp ############## 
Ref_comp <- sqlQuery(db, paste (sql_ref)) 
########################################## 
odbcClose(data_testeur) 

#### An other SQL Query for the graph ####### 

graph <- ggplot(... 
ggplotly(graph) # Print graph 
} 

) 
    }) 

여러분의 도움에 감사드립니다 내 Server.R

+0

서버 코드에 쿼리가있는 데이터 프레임 개체가 Shiny UI에서 발견됩니까? 나는 범위 객체 간의 UI와 서버를 의미한다. –

답변

0

귀하의 문제는 당신이 Ref_comp이 우리가 가진 역동적 selectInput을 생성해야하는 경우가있을 때 server.r에서 생성되는 data_frame 이 같은 renderUIuiOutput() :

shinyUI(pageWithSidebar(

    headerPanel("My header Text"), 
    sidebarPanel( 
    radioButtons("test", "Select a DataBase", 
       c("test1"="test1", 
        "test2"="test2")), 
    textInput("card", "Enter the code card", "CARD.EX"), 
    textInput("comp", "Enter the ref comp", "R3"), 
    ######## Here what I tried to do ######## 
    uiOutput("selectComp"), 
    ########################################## 
    downloadButton("plot_export", "Save PDF") 
), 

    mainPanel(
    #h4("Text2"), 
    library(plotly), 
    plotlyOutput("plot")) 


)) 

와 서버를

shinyServer(function(input,output){ 

    refDataFrame <- reactive({ 
    con <- odbcConnect(con, uid="xxx") 

    ##### Here the SQL Query to have my items ###################### 
    sql_ref = paste("select DISTINCT ...") # My SQL query on distant server 
    ###### Output in DF Ref_comp ############## 
    Ref_comp <- sqlQuery(db, sql_ref) 
    odbcClose(data_testeur) 
    Ref_comp 
    }) 

    output$selectComp <- renderUI(
    selectInput("comp_sel","Component", choices= 
        as.character(unique(unlist(refDataFrame()[["STEP_NAME"]])))) 
) 

    output$plot <- renderPlotly({ 
    Ref_comp <- refDataFrame() 

    #### An other SQL Query for the graph ####### 

    graph <- ggplot(...) 
        ggplotly(graph) # Print graph 
    } 

    ) 
}) 

이제는 데이터베이스 쿼리 결과가 두 곳에서 별도의 리액션 함수에 포함되어야합니다.

관련 문제