[英]Shiny with SelectInput from a dataframe column
I tried to read dataframe rows from one column to feel a list in a SelectInput objet in a UI.R Shiny I have a problem with global or local ref between the UI and Server and I don't know if the format is right to import items in the selectInput List 我试图从一列读取数据帧行以在UI.SelectInput对象中感觉到一个列表.R闪闪发光我在UI和Server之间存在全局或局部引用问题,我不知道该格式是否适合导入selectInput列表中的项目
Here my DF Ref_comp with just one column (STEP_NAME): 在这里,我的DF Ref_comp只有一列(STEP_NAME):
! STEP_NAME !
-----------------
L1_2_3_LR
C46-C77-OTHERS
R4
R10
C56
Q4
L4
Here my UI.R 这是我的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"))
))
Here my Server.R 这是我的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
}
)
})
Thank you for your help 谢谢您的帮助
Your problem is that you the data_frame Ref_comp is generated in server.r when this is the case we have to generate the selectInput dynamic with a renderUI
and uiOutput()
like this: 您的问题是,在这种情况下,我们必须使用renderUI
和uiOutput()
生成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"))
))
and server 和服务器
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
}
)
})
Since we now need the result of the database query in two places have put it in a separate reactive function 由于我们现在需要将数据库查询的结果放在两个地方,因此将其放在单独的反应函数中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.