无法动态填充下拉菜单在R闪亮 [英] Cannot populate drop down menu dynamically in R shiny
本文介绍了无法动态填充下拉菜单在R闪亮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用R Shiny创建一个APP。我想上传数据(.csv文件)。然后,我想在下拉菜单中填充CSV文件中的列名称。我不能这样做。
I am trying to create an APP using R Shiny. I want to upload data (.csv file). Then I want to populate the column names in CSV file in a drop down menu. I am unable to do that.
请参考以下代码:
----服务器。 r -----
---- server.r -----
library(shiny)
options(shiny.maxRequestSize = 32*1024^2)
shinyServer(
function(input, output){
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file=file1$datapath,head=TRUE,sep=",")
})
output$sum <- renderTable({
if(is.null(data())){return ()}
summary(data())
})
output$table <- renderTable({
if(is.null(data())){return ()}
data()
})
# the following renderUI is used to dynamically generate the tabsets when the file is loaded. Until the file is loaded, app will not show the tabset.
output$tb <- renderUI({
if(is.null(data()))
h5("no file loaded")
else
tabsetPanel(tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum")))
})
output$col <- renderUI({
selectInput("phenomena", "Select the Phenomena", names(data))
})
})
----- ui.R -----
----- ui.R -----
library(shiny)
shinyUI(fluidPage(
titlePanel("Hotspot Analysis of EnviroCar Data"),
sidebarLayout(
sidebarPanel(
# uploading the file
fileInput("file","Upload *.csv file"), # fileinput() function is used to get the file upload contorl option
uiOutput("col")
),
mainPanel( uiOutput("tb") )
)
))
推荐答案
我想问题出在 server.R
:
selectInput("phenomena", "Select the Phenomena", names(data))
这里,你使用没有括号的 data
,所以你实际获得的是函数的源代码 data
,
names(data)
是 NULL
。我想你所需要的是用 names(data())
替换名称(数据)
。
Here, you're using data
without parentheses so what you actually obtain is the source code of the function data
, and names(data)
is NULL
. I think all you need is to replace names(data)
by names(data())
.
这篇关于无法动态填充下拉菜单在R闪亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文