在我的数据框中选择一列来创建折线图
Choosing a column in my dataframe to create line chart
我的数据集有三列。一列用于时间,另外两列用于温度测量(Temp1、Temp2)。
我希望能够 select Temp1 或 Temp2 并绘制时间序列图,但我不确定如何在我的 server.R 代码中做到这一点。我的 dygraph 函数调用中应该包含什么?
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
library(shiny)
library(dygraphs)
shinyServer(function(input, output) {
output$TempData <- renderDygraph({
data <- switch(input$data,
"Temp 1" = Data1$Temp1,
"Temp 2" = Data1$Temp2),
dygraph(data, main = "Temperature Rise Data") %>%
**I'm not sure what goes in here**
})
})
这里是ui.R
# This is the user-interface definition of a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
library(shiny)
library(dygraphs)
shinyUI(fluidPage(
# Application title
titlePanel("Temperature Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("data", label = "Choose a Dataset",
choices = c("Temp 1", "Temp 1"),
selected = "Temp 1" ))
),
# Show a plot of the generated distribution
mainPanel(
dygraphOutput("TempData")
)
)
)
据我所知,这应该能满足您的需求?
我强制将 Scan
强制转换为 Date
以使其兼容 - 不确定这是否是最好的方法,但它至少可以让你暂时用这些数据生成基本的 dygraphs - 你可能想进一步研究轴的格式。
...
data <- switch(input$data,
"Temp 1" = as.xts(Data1$Temp1, order.by = as.Date(Data1$Scan))
"Temp 2" = as.xts(Data1$Temp2, order.by = as.Date(Data1$Scan))
dygraph(data, main = "Temperature Rise Data")
...
我的数据集有三列。一列用于时间,另外两列用于温度测量(Temp1、Temp2)。
我希望能够 select Temp1 或 Temp2 并绘制时间序列图,但我不确定如何在我的 server.R 代码中做到这一点。我的 dygraph 函数调用中应该包含什么?
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
library(shiny)
library(dygraphs)
shinyServer(function(input, output) {
output$TempData <- renderDygraph({
data <- switch(input$data,
"Temp 1" = Data1$Temp1,
"Temp 2" = Data1$Temp2),
dygraph(data, main = "Temperature Rise Data") %>%
**I'm not sure what goes in here**
})
})
这里是ui.R
# This is the user-interface definition of a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
library(shiny)
library(dygraphs)
shinyUI(fluidPage(
# Application title
titlePanel("Temperature Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("data", label = "Choose a Dataset",
choices = c("Temp 1", "Temp 1"),
selected = "Temp 1" ))
),
# Show a plot of the generated distribution
mainPanel(
dygraphOutput("TempData")
)
)
)
据我所知,这应该能满足您的需求?
我强制将 Scan
强制转换为 Date
以使其兼容 - 不确定这是否是最好的方法,但它至少可以让你暂时用这些数据生成基本的 dygraphs - 你可能想进一步研究轴的格式。
...
data <- switch(input$data,
"Temp 1" = as.xts(Data1$Temp1, order.by = as.Date(Data1$Scan))
"Temp 2" = as.xts(Data1$Temp2, order.by = as.Date(Data1$Scan))
dygraph(data, main = "Temperature Rise Data")
...