Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 发光应用中的Ploly图形是一条平线,而不是工作散点图_R_Shiny_Plotly_R Plotly - Fatal编程技术网

R 发光应用中的Ploly图形是一条平线,而不是工作散点图

R 发光应用中的Ploly图形是一条平线,而不是工作散点图,r,shiny,plotly,r-plotly,R,Shiny,Plotly,R Plotly,我正在使用shiny创建一个下拉框,您可以在其中选择一个项目。选择该项目后,将显示一个绘图仪。当我单独运行plotly graph时,我会得到一个好看的散点图,但当我在闪亮的应用程序中运行它时,我会在这三个项目上得到一条直线 这是plotly代码,在自己运行时可以工作: library(plotly) plot_ly(df1, x = ~time, y = ~item1, color = ~item1) %>% add_lines(name = ~"item1") 这是数据集的外观,共

我正在使用shiny创建一个下拉框,您可以在其中选择一个项目。选择该项目后,将显示一个绘图仪。当我单独运行plotly graph时,我会得到一个好看的散点图,但当我在闪亮的应用程序中运行它时,我会在这三个项目上得到一条直线

这是plotly代码,在自己运行时可以工作:

library(plotly)
plot_ly(df1, x = ~time, y = ~item1, color = ~item1) 
%>% add_lines(name = ~"item1")
这是数据集的外观,共有4列26949行:

      time                      item1    item2    item3
1     2018-04-09 00:00:06        615       NA       NA
2     2018-04-09 00:00:08         NA      465       NA
3     2018-04-09 00:00:08         NA       NA       NA
4     2018-04-09 00:00:10         NA       NA      422
5     2018-04-09 00:00:13         NA       NA       NA
6     2018-04-09 00:00:21        522       NA      385
7     2018-04-09 00:00:25         NA       NA       NA
....  ....                       ....     ....     ...
26949 2018-04-09 23:59:59        323       NA      200
代码如下:

#Import libraries
library(shiny)
library(plotly)

# Define UI for the application
ui <- bootstrapPage(

selectInput(inputId = "n_breaks",
            label = "Select Item:",
            choices = c("item1", "item2", "item3"),
            selected = "item1"),

plotlyOutput(outputId = "main_plot", height = "300px")

)

# Define server logic
server <- function(input, output) {

#Import data
df = read.csv("item_list.csv")

output$main_plot <- renderPlotly({

#Plotly graph
plot_ly(df, x = ~time, y = ~input$n_breaks, color = ~input$n_breaks) %>%
  add_lines(name = ~input$n_breaks)
})
}

# Run the application 
shinyApp(ui = ui, server = server)
#导入库
图书馆(闪亮)
图书馆(绘本)
#定义应用程序的UI

ui您应该将
绘图功能编写为:

plot_ly(df, x = ~time, 
        y = df[, input$n_breaks], 
        color = df[, input$n_breaks]) %>%
        add_lines(name = ~input$n_breaks)
或者稍微短一点,比如:

plot_ly(x = df[, "time"], 
        y = df[, input$n_breaks], 
        color = df[, input$n_breaks]) %>%
        add_lines(name = ~input$n_breaks)

工作起来很有魅力@DJack。非常感谢。不客气。如果你认为它解决了你的问题,考虑接受答案关闭问题(StAdvOx.com /帮助/某人回答),接受它。还是有点新鲜,谢谢你提醒我!