首页 > 解决方案 > 使用 RDS 数据创建闪亮的情节

问题描述

我是一名学习数据科学的数学学生。我试图让用户决定将哪些列用于图表(情节),不幸的是,图表是空白的。

我希望图表是散点图或线图,以显示日期与 nbrskieur 作为默认值,并能够根据用户的偏好更改 x、y 或两者。我无法找到任何关于如何使用 RDS 中用户选择的列进行绘图的教程或答案。

帮助将不胜感激,谢谢

library(shiny)
library(plotly)

# Define UI for the application that draws a plotly from RDS data
ui <- fluidPage(
    
    # App title ----
    titlePanel("ploting RDS data"),
    
    # Sidebar layout with input and output definitions ----
    sidebarLayout(
        
        # Sidebar panel for inputs ----
        sidebarPanel(
            
            # Input: Select a file ----
            fileInput("file1", "Choose rds File",
                      multiple = FALSE,
                      accept = ".rds"),
            selectInput("var1","select the x variable from the file", choices = c("Date","jour","report","noubre de skieur","ndemj", "nbrtotal")),
            selectInput("var2","select the y variable from the file", choices = c("Date","jour","report","noubre de skieur","ndemj", "nbrtotal")),
            ),
        
        # Main panel for displaying outputs ----
        mainPanel(
            plotlyOutput("skieurdist")
        )
        
    )
)

# Define server logic required to draw a plotly with default columns of dates and nbrskieur(number of skiers)
server <- function(input, output) {
    output$skieurdist <- renderPlotly({
        tbl_rds <- readRDS(input$file1$datapath)
        plot.obj <<-list()
        plot.obj$tbl_rds <<- tbl_rds
        xcol <- as.numeric(input$var1)
        ycol <- as.numeric(input$var2)
        #p <- plot_ly(plot.obj$table_rds, x = input$var2, y = ycol, type = "scatter")
        skieur <- plot_ly(plot.obj$tbl_rds, x = xcol, y = ycol, type = "bar")
        # p %>%  layout(legend = list(x = 1, y = 0.5 , bgcolor = "#E2E2E2"))
        #require(input$submit)
    })
}

# Run the application 
shinyApp(ui = ui, server = server)
[here is some example of the data that I have][1]```


  [1]: https://i.stack.imgur.com/AcZsP.png

标签: rgraphshinyplotly

解决方案


推荐阅读