r - 使用 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
解决方案
推荐阅读
- mysql - 每次创建表列并点击保存时都会出错
- corda - Corda - 可以在生产环境中部署使用 Corda V1.0 构建的 CorDapp 吗?
- c++ - q-learning 计算中的大量状态
- javascript - 由于登录用户如何编辑表记录
- laravel - 使用 laravel 连接到亚马逊 aws 时出错
- google-maps - 谷歌地图未显示在百里香中
- c# - 迁移到 Swashbuckle.AspNetCore 版本 5 时,Swagger UI 中的不记名身份验证
- amazon-web-services - 指定位置的脚本:以 root 用户身份运行的脚本/stop_server.sh 失败,退出代码为 126
- compiler-construction - 解析没有参数分隔符的函数参数
- python - 停止索引太多