繁体   English   中英

从Dataframe列使用SelectInput发光

[英]Shiny with SelectInput from a dataframe column

我试图从一列读取数据帧行以在UI.SelectInput对象中感觉到一个列表.R闪闪发光我在UI和Server之间存在全局或局部引用问题,我不知道该格式是否适合导入selectInput列表中的项目

在这里,我的DF Ref_comp只有一列(STEP_NAME):

!   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"))


     ))

这是我的Server.R

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
 }

 ) 
  })

谢谢您的帮助

您的问题是,在这种情况下,我们必须使用renderUIuiOutput()生成selectInput动态,从而在server.r中生成renderUI uiOutput()

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
  }

    ) 
})

由于我们现在需要将数据库查询的结果放在两个地方,因此将其放在单独的反应函数中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM