我有一个日期框架file1,其中col V2包含时间,V3-V13是参数。
我想绘制时间与R闪亮的参数。我能够得到摘要和表值,但在绘图中它表示"未定义的列被选中"。任何指针都会有所帮助。
摘要和表格值按预期进行
下面是我的UI.R和Server.R
- SERVER.R
server <- function(input, output) {
file1 = read.csv(file = "RawData_METHODIST_WOODLANDS_MethodistWoodlands_ YK
CH1_1_4_2017_to_27_04_2017_new.csv", header = FALSE)
as.data.frame(file1)
# Return the requested dataset ----
file <- reactive({
switch(input$sel,
"WAR-CODE ( States )" = file1$V3,
"VSD-CONVHS-T ( degF )" = file1$V4,
"MANUAL PRV % OPEN ( % )" = file1$V5,
"WIND SPEED ( mph )" = file1$V6,
"REFPOS-SP ( % )" = file1$V7,
"MOT-FLA ( % )" = file1$V8,
"LL-SV-STS ( offon )" = file1$V9,
"TEMPERATURE ( degF )" = file1$V10,
"EVAP-P ( psi )" = file1$V11,
"VSD OP-Hz ( hz )" = file1$V12,
"MANUAL EVAP RETURN PRESSURE ( psi )" = file1$V13)
})
# Generate a summary of the dataset ----
output$summary <- renderPrint({
file1 <- file()
summary(file1)
})
output$plot1 <- renderPlot({
print(input$sel)
file1 <- file()
file1 <- as.data.frame(file1)
Time1 = strptime(file1$V2,format = "%Y-%m-%d %H:%M:%S")
plot(Time1,file1[,input$sel])
})
# Show the first "n" observations ----
output$view <- renderTable({
head(file(), n = input$obs)
head(file(), n = input$obs)
})
}
- UI.R
# Define UI for dataset viewer app ----
ui <- fluidPage(
# App title ----
titlePanel("PLOTS FOR JCI"),
# Sidebar layout with a input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Selector for choosing dataset ----
selectInput(inputId = "sel",
label = "Choose a Parameter:",
choices = c("WAR-CODE ( States )" , "VSD-CONVHS-T ( degF )",
"MANUAL PRV % OPEN ( % )","WIND SPEED ( mph )","REFPOS-SP ( % )","MOT-FLA
( % )","LL-SV-STS ( offon )","TEMPERATURE ( degF )", "EVAP-P ( psi )","VSD
OP-Hz ( hz )","MANUAL EVAP RETURN PRESSURE ( psi )")),
# Input: Numeric entry for number of obs to view ----
numericInput(inputId = "obs",
label = "Number of observations to view:",
value = 10)
),
# Main panel for displaying outputs ----
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Plot", plotOutput("plot1")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("view"))
)
)
)
)
shinyApp(ui,server)
答案 0 :(得分:0)
基于虚拟数据:
library(shiny)
file1 = data.frame(V1=0:10, V2=12:22, V3=15:25)
Time1 = file1$V2
server <- function(input, output) {
output$plot1 <- renderPlot({
plot(Time1,file1[, input$sel])
})
}
# Define UI for dataset viewer app ----
ui <- fluidPage(
# App title ----
titlePanel("PLOTS FOR JCI"),
# Sidebar layout with a input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Selector for choosing dataset ----
selectInput(inputId = "sel",
label = "Choose a Parameter:",
choices = c("V1" , "V2", "V3"))
),
# Main panel for displaying outputs ----
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Plot", plotOutput("plot1"))
)
)
)
)
shinyApp(ui,server)
答案 1 :(得分:0)
终于工作了。我使用了如下的renderplot()。
output$plot1 <- renderPlot
({
plot(Time1,file())
})