pac*_*met 22 r shiny shiny-server
我有一个闪亮的应用程序,显示我的数据的一个很好的html表,使用renderDataTable.然后我想做一些基本的统计,子集数据和计算方法以及其他一些数据.
显示结果时renderTable,我发现日期列未显示日期格式.在图中你可以看到差异.两个表都是从同一个闪亮的Web应用程序中的相同数据集生成的.你能解释一下发生了什么吗?

在这里你可以看到ui.R和server.R.在这个脚本中我只想显示一个表,并对不同的输出感到惊讶.
ui.R
library(shiny)
# Estructura de la página (paneles)
shinyUI(pageWithSidebar(
# Título superior
headerPanel(""),
# Panel lateral izquierdo - selección de datos
sidebarPanel(
helpText("Selecciona las fechas y el tipo de datos.
Pulsa el botón Actualizar."),
selectInput("torre", "Torre:",
list("Agres" = "mariola",
"Alfàs del Pi" = "shelada",
"Altura" = "altura",
"Vistabella del Maestrat" = "vistabella",
"Xàtiva" = "xativa")),
selectInput("tipo", "Intervalo de datos",
list("Diezminutales" = "-datos-10m.csv",
"Diarios" = "-datos-diarios.csv",
"Mensuales" = "-datos-mensuales.csv")),
dateInput('date1',
label = 'Fecha inicial',
value = Sys.Date()),
dateInput('date2',
label = 'Fecha final.',
value = Sys.Date()),
submitButton("Actualizar"),
helpText("
Descarga de datos tabulados en formato CSV."),
downloadButton('downloadData','Descargar datos')
),
# Panel principal (presentación de gráficas)
mainPanel(
tabsetPanel(
tabPanel("Inicio",
h3("Consulta de datos"),
p(HTML("Some info.")),
tableOutput("view")
),
tabPanel("Ayuda", htmlOutput("ayuda"),id="ayuda"),
tabPanel('Tabla de datos', dataTableOutput("table1")),
tabPanel('Medias', tableOutput("table2"))
)
)
))
Run Code Online (Sandbox Code Playgroud)
和server.R
library(shiny)
library(plyr)
library(lubridate)
library(scales)
options(shiny.transcode.json = FALSE)
# Funciones
shinyServer(function(input,output){
filename=reactive({
paste0(input$torre,input$tipo)
})
day1=reactive({
as.POSIXct(input$date1)
})
day2=reactive({
as.POSIXct(input$date2)
})
# Ayuda
introFile <- './ayuda.txt'
ayuda <- readChar(introFile, file.info(introFile)$size)
output$ayuda <- renderText({HTML(ayuda)})
datos2=reactive({
fn = filename()
f = read.csv(fn,header=T, sep=",",na.strings="-99.9")
f$date = as.Date(f$date)
f
})
datos=reactive({
d1 <- as.Date(day1())
d2 <- as.Date(day2())
datos2a = datos2()
with( datos2a , datos2a[ date >= d1 & date <= d2, ] )
})
# Tabla de datos
output$table1 = renderDataTable({
datos()
}, options = list(aLengthMenu = c(12, 20, 40), iDisplayLength = 12))
output$table2 = renderTable({
datos()
})
output$downloadData <- downloadHandler(
file = c('data.csv'),
content = function(file) {
write.csv(datos(), file)
}
)
})
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助
ags*_*udy 23
没有理由从2个不同的功能获得相同的输出.
rendertable用于xtable创建html表renderDataTable 使用外部JavaScript库 您可以获得相同的日期格式,您应该在致电之前格式化日期renderTable.这是一个简短的完整例子.
library(shiny)
dat <- data.frame(date=seq.Date(Sys.Date(),by=1,length.out=5),
temp = runif(5))
ui <- fluidPage(
fluidRow(column(4,dataTableOutput('dto')),
column(4,tableOutput('to')))
)
server <- function(input,output){
output$dto <- renderDataTable({dat})
dat$date <- format(dat$date,'%Y-%m-%d')
output$to <- renderTable(dat)
}
runApp(list(ui=ui,server=server))
Run Code Online (Sandbox Code Playgroud)