我很难弄清楚为什么我的列和日期时间列的过滤器显示错误的日期和时间。
我的数据看起来像这样(dput 在下面的闪亮代码中):
DATUM NUMMER
1 2017-03-29 00:00:02 19
2 2017-03-29 00:00:36 20
3 2017-03-29 00:00:40 21
4 2017-03-29 00:00:44 22
5 2017-03-29 00:00:47 23
6 2017-03-29 00:00:51 24
7 2017-03-29 00:00:55 25
8 2017-03-29 00:00:59 26
9 2017-03-29 00:01:03 27
10 2017-03-29 00:01:07 28
Run Code Online (Sandbox Code Playgroud)
正如我们所看到的,这没什么特别的。在闪亮的 using 包中显示此数据后DT,数据如下所示:
显示有2小时的差异,没有任何原因......
我的第一个方法是检查我的Sys.time()
> Sys.time()
[1] "2017-03-30 09:09:40 CEST"
Run Code Online (Sandbox Code Playgroud)
这是正确的,第二种方法是深入研究DT文档,我在那里找到了该函数:formatDate(1, method = 'toLocaleString')。我已经使用过它,日期时间字段的显示似乎很好(见下图),但是顶部过滤器仍然显示错误的日期时间值......
这是可重现的示例:
library(shiny)
library(DT)
data <- …Run Code Online (Sandbox Code Playgroud) 我将根据样本数据向您解释我的问题.这是第一个表(df1):
x x1 y z
1 1 10 a 11
2 3 11 b 13
3 5 10 c 15
4 7 11 d 17
5 9 10 e 19
Run Code Online (Sandbox Code Playgroud)
这是一个dput()版本:
structure(list(x = c(1, 3, 5, 7, 9), x1 = c(10, 11, 10, 11, 10
), y = structure(1:5, .Label = c("a", "b", "c", "d", "e"), class = "factor"),
z = c(11, 13, 15, 17, 19)), .Names = c("x", "x1", "y", "z"
), row.names = c(NA, …Run Code Online (Sandbox Code Playgroud) 我还没有找到关于Shiny中ProgressBar的问题的解决方案,用于从数据库加载数据.我的Shiny App连接到数据库,用户直接从那里获取数据(因为我的SQL查询是被动的,数据量不同).有时数据很大,加载需要一些时间.用户不知道是否有什么事情发生或应用程序"卡住".我在我的应用程序(在output$tabelle <- DT::renderDataTable({...中)实现了最简单的流程指标,但似乎还不够:
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(message = "Processing", value = 0)
Run Code Online (Sandbox Code Playgroud)
用户仍然有点困惑.
我想像这样smthg(在R中显示状态消息)使用?tcltk::tkProgressBar:
pb <- tkProgressBar("test progress bar", "Some information in %",
0, 100, 50)
Sys.sleep(0.5)
u <- c(0, sort(runif(20, 0 ,100)), 100)
for(i in u) {
Sys.sleep(0.1)
info <- sprintf("%d%% done", round(i))
setTkProgressBar(pb, i, sprintf("test (%s)", info), info)
}
Sys.sleep(5)
close(pb)
Run Code Online (Sandbox Code Playgroud)
有一些百分比评估从数据库加载数据的进度.
我不知道如何在我闪亮的应用程序中使用它.任何想法都会有所帮助.
提前致谢!
*一些简单的应用:
library("shiny")
library("DT")
shinyApp(
ui = fluidPage(DT::dataTableOutput('tbl')),
server = function(input, output) {
output$tbl = DT::renderDataTable(
iris) …Run Code Online (Sandbox Code Playgroud) 我需要根据另一列(SEQ)获得行的中值.让我根据样本数据解释你:
data <- structure(list(DATUM = structure(c(1335558400, 1335558400, 1335558400,
1335558400, 1335562429, 1335562429, 1335562429, 1335562429, 1335562429,
1335562429, 1335562429, 1335562429, 1335562429, 1335562429, 1335562429,
1335567274, 1335567274, 1335567274, 1335567274, 1335567274, 1335567274,
1335567274, 1335567274, 1335567274, 1335567274, 1335567274, 1335681543,
1335681543, 1335681543, 1335681543), class = c("POSIXct", "POSIXt"
)), CHGNR = c(200028, 200028, 200028, 200028, 200029, 200029,
200029, 200029, 200029, 200029, 200029, 200029, 200029, 200029,
200029, 200029, 200029, 200029, 200029, 200029, 200029, 200029,
200029, 200029, 200029, 200029, 200057, 200057, 200057, 200057
), SEQ = c(1L, 1L, 1L, 1L, 1L, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建能够显示交互式绘图标题的Shiny App(取决于x轴的选择值)
很简单的例子:
library(shiny)
library(DT)
library(ggplot2)
x <- as.numeric(1:1000000)
y <- as.numeric(1:1000000)
z <- as.numeric(1:1000000)
data <- data.frame(x,y, z)
shinyApp(
ui = fluidPage(selectInput(inputId = "yaxis",
label = "Y-axis",
choices = list("x","y","z"),
selected = c("x")),
dataTableOutput('tableId'),
plotOutput('plot1')),
server = function(input, output) {
output$tableId = renderDataTable({
datatable(data, options = list(pageLength = 10, lengthMenu=c(10,20,30)))
})
output$plot1 = renderPlot({
filtered_data <- data[input$tableId_rows_all, ]
ggplot(data=filtered_data, aes_string(x="x",y=input$yaxis)) + geom_line()
})
}
)
Run Code Online (Sandbox Code Playgroud)
我试过这段代码:
ggtitle("Line plot of x vs",input$yaxis)
Run Code Online (Sandbox Code Playgroud)
它没有工作,情节没有显示,给我一个错误:
Warning: Error in ggtitle: unused argument (input$yaxis) …Run Code Online (Sandbox Code Playgroud) 我想从用户单击小部件时删除初始值( selected=) 。selectizeInput
这是示例代码:
library(shiny)
library(dplyr)
ui= fluidPage(
sidebarLayout(
sidebarPanel(
selectizeInput(inputId= "cyl", label= "cyl",
choices= NULL,
selected= sort(unique(mtcars$cyl))[1],
multiple=T)
),
mainPanel(
tableOutput("tab")
)
)
)
server= function(input, output,session) {
updateSelectizeInput(session = session,inputId ="cyl",choices=sort(unique(mtcars$cyl)),selected=sort(unique(mtcars$cyl))[1], server = TRUE)
df_filtered= reactive({
mtcars %>%
{if (is.null(input$cyl)) . else filter(., cyl %in% input$cyl)}
})
output$tab= renderTable(df_filtered())
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
只是基于示例代码的一些解释:
selectizeInput "cyl"中的初始选定值为4。当用户按下此小部件时,我希望4 删除该值并selected清除该选项。有任何想法吗?
*我使用了该功能,updateSelectizeInput因为server在我的shiny app选择中选择很大导致加载时间太长