【发布时间】:2019-07-18 07:49:49
【问题描述】:
我想制作一个应用程序,用户可以在其中加载一些数据,而不是自己探索它,所以,我现在想知道如何将数据集的 colnames 传递给selectInput
为此,我有一个像这样的简单应用程序:
library("shiny")
library("readxl")
# Define UI
ui <- fluidPage(
titlePanel("TKM"),
sidebarLayout(
sidebarPanel(
fileInput(inputId = "input",label = "input xlsx: ", multiple = FALSE, accept = c(".xlsx"))
),
mainPanel(
tableOutput("contents")
)
)
)
# Define server logic
server <- function(input, output) {
df <- reactive({ read_xlsx(input$input$datapath) })
output$contents <- renderTable({ head(df()) })
}
# Run the application
shinyApp(ui = ui, server = server)
所以,如您所见,我的数据是一个反应输入,所以如果我添加一个简单的:
selectInput(inputId = "x", label = "X: ", choices = colnames(df()))
我将无法运行以下应用:
Error in df() : argument "x" is missing, with no default
任何 idias 我如何将我的 df 的名称传递给 selectInput?
【问题讨论】:
-
请看
?df(函数来自library(stats)):Density, distribution function, quantile function and random generation for the F distribution。请使用例如DF改为您的响应式名称。 -
您需要使用动态 UI。看看
uiOutput。示例:shiny.rstudio.com/gallery/dynamic-ui.html
标签: r shiny shiny-reactivity