【发布时间】:2016-09-08 05:12:34
【问题描述】:
我正在尝试设置一个相对基本的闪亮应用程序,我有一个包含日期列 (DF$Date) 的数据框,我想:(1) 设置 dateRangeInput 以获得最小值和最大值DF$Date (2) tableOutput 应该只打印选择的日期范围。
这是我正在使用的代码:
UI.R
library(shiny)
library(shinydashboard)
library(plyr)
library(reshape2)
#library(data.table)
shinyUI(pageWithSidebar(
headerPanel("CSV Viewer"),
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv')),
tags$hr(),
checkboxGroupInput("inCheckboxGroup",
"Checkbox group input:",
choices = NULL
),
actionButton("oui","Affichage"),
actionButton("non","Clear"),
numericInput("act1", "afficher les dernieres lignes:",10),
uiOutput("choose_columns"),
uiOutput("date")
),
mainPanel(
uiOutput("dates"),
tableOutput('contents'),
verbatimTextOutput('mean')
)
))
服务器.UI
shinyServer(function(input, output,session) {
dsnames <- c()
######### essai date ###############
###################
output$dates <- renderUI({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
dates <- as.Date(data_set()$Date,origin="2002-10-01", format = "%d %b %y")
minval <- min(dates)
maxval <- max(dates)
dateRangeInput('expDateRange', label = "Choose experiment time-frame:",
start = minval, end = maxval,
min = minval, max = maxval,
separator = " - ", format = "yyyy-mm-dd",
language = 'cz', weekstart = 1)
})##################################
####################################
data_set <- reactive({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
data_set<-data.frame(tail(read.csv(inFile$datapath, header = TRUE, sep = ";", dec = ","), n=input$act1))
data_set
})
###########ici observe contents []###################
observe({if(input$oui)
output$contents <- renderTable({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
format( data_set()[, input$inCheckboxGroup], nsmall=5)
})
})
observe(if(input$non) output$contents<- renderTable(NULL))
#############################################
output$mean<-renderPrint({
inFile <- input$file1
if (is.null(inFile))
return("choisissez le fichier et decocher la date")
inFile <- input$file1
data<- data_set()[, input$inCheckboxGroup]
a<-colMeans(data[,which(sapply(data, class) != "Date")])
moyenne<-round(a*100,5)
data.frame(moyenne)
})
observe({
dsnames <- names(data_set())
cb_options <- list()
cb_options[ dsnames] <- dsnames
updateCheckboxGroupInput(session, "inCheckboxGroup",
label = "Check Box Group",
choices = cb_options,
selected = cb_options)
})
output$choose_dataset <- renderUI({
selectInput("dataset", "Data set", as.list(data_sets))
})
# Check boxes
output$choose_columns <- renderUI({
# If missing input, return to avoid error later in function
if(is.null(input$data_set))
return()
# Get the data set with the appropriate name
colnames <- names(contents)
# Create the checkboxes and select them all by default
checkboxGroupInput("columns", "Choose columns",
choices = colnames,
selected = colnames)
})
})
我正在使用的数据:
Date VL s d performance
28/12/2015 1082,71 3,67 0,0005 -0,0002
04/01/2016 1081,78 3,67 0,0005 0.0007
08/01/2016 1082,27 4,03 0,0031 0,0008
15/01/2016 1082,76 4,06 0,0013 0,0009
22/01/2016 1086,08 4,41 0,0042 0,0014
29/01/2016 1087,5 4,58 0,0016 0,0015
05/02/2016 1092,02 5,81 0,003 0,0016
12/02/2016 1093,8 6,6 0,006 0,0021
19/02/2016 1097,05 6 0,0016 0,0021
26/02/2016 1103,63 5,02 0,0019 0,0021
04/03/2016 1105,35 4,79 0,0024 0,0021
11/03/2016 1107,45 3,36 0,0074 0,0025
18/03/2016 1110,16 4,83 0,0112 0,0031
任何提示都可能有用,请让我卡住。谢谢。
【问题讨论】:
-
发布您的数据样本,而您目前正在开发的应用程序是获得帮助的最佳方式。
-
使用
dput(DF$Date)接收可导出的结构。 -
您需要用英语解释以下内容的含义:“我希望用户能够查看两个日期之间的行”。我们缺乏背景和具体目标。