output$paintplot <- renderPlotly({
validate(need(input$ProductLine, ""))
if(is.null(input$dateMonth)){return(NULL)}
if(input$select == "日") {
p <- ggplot(data = p_A, aes(x = time, y = visit)) + xlab("時間") + ylab("關注度") + ggtitle(paste("折線圖-", input$dateMonth, "日")) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
df <- data.frame(A_date[[input$dateMonth]])
df2 <- data.frame(B_date[[input$dateMonth]])
df3 <- data.frame(C_date[[input$dateMonth]])
df4 <- data.frame(D_date[[input$dateMonth]])
df5 <- data.frame(E_date[[input$dateMonth]])
df6 <- data.frame(visits_Frame_data[[input$dateMonth]])
if(any(input$ProductLine == "iPhone 7")) {
if(length(df$date)==0){
return(NULL)
}
p <- p + geom_point(data = df, size = 2, color="green", aes(text = "Item: iPhone 7")) + geom_line(data = df, color="green", aes(text = "Item: iPhone 7"))
}
if (any(input$ProductLine == "iWatch 2")) {
if(length(df2$date)==0){
return(NULL)
}
p <- p + geom_point(data = df2, size = 2, color="red", aes(text = "Item: iWatch 2")) + geom_line(data = df2, color="red", aes(text = "Item: iWatch 2"))
}
if (any(input$ProductLine == "USB 3.0 64G")) {
if(length(df3$date)==0){
return(NULL)
}
p <- p + geom_point(data = df3, size = 2, color="blue", aes(text = "Item: USB 3.0 64G")) + geom_line(data = df3, color="blue", aes(text = "Item: USB 3.0 64G"))
}
if (any(input$ProductLine == "PS3")) {
if(length(df4$date)==0){
return(NULL)
}
p <- p + geom_point(data = df4, size = 2, color="#58D3F7", aes(text = "Item: PS3")) + geom_line(data = df4, color="#58D3F7", aes(text = "Item: PS3"))
}
if (any(input$ProductLine == "Sony XZ")) {
if(length(df5$date)==0){
return(NULL)
}
p <- p + geom_point(data = df5, size = 2, color="#FA58F4", aes(text = "Item: Sony XZ")) + geom_line(data = df5, color="#FA58F4", aes(text = "Item: Sony XZ"))
}
if (any(input$ProductLine == "test")) {
if(length(df6$date)==0){
return(NULL)
}
p <- p + geom_point(data = df6, size = 2, color="#B292EA", aes(text = "Item: test")) + geom_line(data = df6, color="#B292EA", aes(text = "Item: test"))
}
ui.R代码:
shinyUI(fluidPage(
includeCSS("css/main.css"),
navbarPage("資料視覺化",
tabPanel("分析圖",
sidebarLayout(
sidebarPanel(
#add choices
selectizeInput("ProductLine", "選擇商品:",
choices = c("Arduino", "iPhone 7", "iWatch 2",
"USB 3.0 64G", "PS3", "Sony XZ"),
multiple = TRUE),
selectInput("select", "選擇顯示方式:",
choices = c("日", "週")),
uiOutput("splitDate"),
uiOutput("weekList")
),
mainPanel(
plotlyOutput("paintplot", width=800,height=600)
)
)
),
tabPanel("長條圖",
sidebarLayout(
sidebarPanel(
#add choices
selectInput("Productbar", "選擇商品:",
choices = c("Arduino", "iPhone 7", "iWatch 2",
"USB 3.0 64G", "PS3", "Sony XZ")),
selectInput("Barselect", "選擇顯示方式:",
choices = c("日", "範圍")),
dateInput("splitDateBar", "選擇日期:", value = Sys.Date()),
uiOutput("hourList"),
tags$p("總平均關注度:"),
textOutput("text1")
),
mainPanel(
plotlyOutput("paintplotbar", width=800,height=600)
)
)
)
)
))
但是我改变了这段代码:
ggplot(data = p_A,aes(x = date,y = visit))+ xlab(&#34;时间&#34;)
我想要第一张图片,但它必须有线条。我能做什么?请帮帮我。感谢。