我正在尝试编写一个闪亮的应用程序以显示列数据。该代码有效,但在RStudio中得到警告消息。
警告如下:
Warning: Error in [.data.frame: undefined columns selected
Stack trace (innermost first):
82: [.data.frame
81: [
80: print
79: renderTable [/media/ubuntu/C2ACA28AACA27895/Windows/work/R/Shiny_Apps/hos_performance/patsatsys.R#40]
78: func
77: origRenderFunc
76: output$tab1
1: runApp
以下是代码:
library(shiny)
library(shinydashboard)
ui <- fluidPage(
navbarPage(title = "PATSATSYS",
tabPanel("DataSets",
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File", accept=c('text/csv', 'text/comma-separated-values', 'text/plain', '.csv')),
selectInput("dcol", "Choose the Column", choices = " ", selected = " ")
),
mainPanel(tableOutput("tab1"))
)
),
tabPanel("Discriptives", textOutput("sum-1")),
tabPanel("Revenue/Cost", textOutput("text-1")),
tabPanel("Performance", textOutput("text-2"))
)
)
server <- function(input, output, session) {
data_input <- reactive({
infile <- input$file1
req(infile)
data.frame(read.csv(infile$datapath))
})
observeEvent(input$file1,{
updateSelectInput(session,
inputId = "dcol",
choices = names(data_input()))
}
)
output$tab1 <- renderTable({
df <- data_input()
print(df[input$dcol])
})
}
shinyApp(ui, server)
我希望代码能够执行而不会发出警告消息。如何清除警告消息?
答案 0 :(得分:0)
这应该做到:
output$tab1 <- renderTable({
data_input()[[input$dcol]]
})