我想根据通过复选框输入动态选择的列来设置我的数据。 有没有什么方法可以让我的输入文件在我的代码 全球可用,以便进一步的操作可以很容易地执行。R shiny:基于复选框组输入的子集数据
以下是我的代码:
Server.R
library(shiny)
shinyServer(function(input, output) {
dInput <- reactive({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
finput <- read.csv(inFile$datapath, header=TRUE, sep=',',quote="'")
fheaders <- names(finput)
return(fheaders)
})
output$choose_columns <- renderUI({
checkboxGroupInput("columns", "Choose columns",
choices = dInput(),
selected = NULL)
})
# to observe in environment which columns are selected
observe({ print(input$columns) })
output$data_table <- renderTable({
# If missing input, return to avoid error later in function
if(is.null(input$file1))
return()
# Get the data set
dat <- get(input$file1)
# Keep the selected columns
dat <- dat[, input$columns, drop = FALSE]
# Return first 20 rows
head(dat, 20)
})
})
ui.R
library(shiny)
# Define UI for application
shinyUI(fluidPage(
# Application title
titlePanel("Subset a table"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
uiOutput("choose_columns")
),
mainPanel(
tableOutput("data_table")
)
)
))
我收到以下错误,同时显示tableOutput( “data_table”)
Error : invalid first argument
在你的'head(dat,20)'声明前加一个'print(input $ columns)'来查看是否选择了正确的列 – SymbolixAU