是否可以在Shiny中有一个下拉列表,您可以在其中选择多个值?我知道selectInput
可以选择设置,multiple = T
但我不喜欢它所有选择的选项在屏幕上都可见,特别是因为我有40以上.同样适用checkboxGroupInput()
,我更喜欢但仍然显示所有选定的值.是不是可以像我从下面的Excel中复制的那样下拉,而不是Shinys selectInput
及其checkboxGroupInput()
后的例子?
我想用lm
函数进行线性回归(或者另一个,如果有效的话).我的因变量是一个叫做的因子AccountStatus
:
拖欠1:0天,拖欠2:30-60天,拖欠3:60-90天,拖欠4:90天.(4)
作为独立变量,我有几个数字变量:贷款到价值,债务到收入和利率.
是否可以使用这些变量进行线性回归?我在互联网上看到了一些关于假人的东西,但这些都是针对自变量的.
这不起作用:
fit <- lm(factor(AccountStatus) ~ OriginalLoanToValue, data=mydata)
summary(fit)
Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的data.table
dt <- data.table(ID=c("A","A","B","B"),Amount1=c(100,200,300,400),
Amount2=c(1500,1500,2400,2400),Dupl=c(1,0,1,0))
ID Amount1 Amount2 Dupl
1: A 100 1500 1
2: A 200 1500 0
3: B 300 2400 1
4: B 400 2400 0
Run Code Online (Sandbox Code Playgroud)
我需要复制Dupl列中包含1的每一行,并将Amount1值替换为该重复行中的Amount2值.除此之外,我需要在Dupl中为重复行提供值2.这意味着它应该如下所示:
ID Amount1 Amount2 Dupl
1: A 100 1500 1
2: A 1500 1500 2
3: A 200 1500 0
4: B 300 2400 1
5: B 2400 2400 2
6: B 400 2400 0
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢!亲切的问候,
蒂姆
是否可以在旁边的水平栏中放置一些物品dashboardHeader
?我知道你可以notificationItem
像这个例子一样放在最右边.但我想使用与dashboardSidebar
添加过滤器等相同的选项.我想在顶部使用这样的过滤器:
我通常会创建一个这样的粉丝图:
n.ahead <- 10
m <- matrix(,nrow = 5000,ncol = 10)
library(fanplot)
m[,1] <- rnorm(5000,0.01,sd = 0.005)
m[,2] <- rnorm(5000,0.02,0.006)
m[,3] <- rnorm(5000,0.03,0.008)
m[,4] <- rnorm(5000,0.04,0.01)
m[,5] <- rnorm(5000,0.06,0.013)
m[,6] <- rnorm(5000,0.1,0.015)
m[,7] <- rnorm(5000,0.11,0.02)
m[,8] <- rnorm(5000,0.13,0.025)
m[,9] <- rnorm(5000,0.14,0.05)
m[,10] <- rnorm(5000,0.18,0.07)
n.ahead <- 10
fancol <- colorRampPalette(c('black', 'white'))
plot(
NULL, type = 'n', lwd = 3, col = 'black',
xlim = c(0, n.ahead), ylab = 'Y', ylim = c(0,max(m)), xlab = 'Year',
las = 1, xaxt = …
Run Code Online (Sandbox Code Playgroud) 当我打开我的闪亮应用程序时,我发现当我缩小到75%时它们看起来更好.如何强制闪亮的应用程序以75%的速度打开,同样在服务器上?我已经尝试过他们在这个链接中提到的内容,但它似乎不起作用.CSS:
.content-wrapper,
.right-side {
background-color: #ffffff;
}
#controls {
zoom: 0.75;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我已经使用Shiny 包中的popify
函数创建了一个弹出窗口shinyBS
。我想在我的过滤器底部弹出一个与我的过滤器本身一样宽的弹出窗口。我在文档中找不到关于此的任何内容。
示例代码:
library(shiny)
library(shinyBS)
shinyApp(
ui =
fluidPage(
sidebarLayout(
sidebarPanel(
tags$span(
popify(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
'a very long popup',"1. I want everything behind 1 on one line and everything that starts after<br> 2. I want to see on the second line without wrapping it to the 3rd line.")),
actionButton("tabBut", "View Table")
),
mainPanel(
plotOutput("distPlot"),
bsModal("modalExample", "Data Table", "tabBut", size = "large",
dataTableOutput("distTable"))
)
) …
Run Code Online (Sandbox Code Playgroud) 我们创建了一个闪亮的应用程序,用户可以上传大数据集(RDB文件超过200MB),也可以从我们这里选择一个.然后有三个不同的选项卡,用户可以在其中过滤数据(数字选项卡,分类选项卡)
所以目前我有3个reactive
功能来实现这个目的.但缺点是对象在内存中保留了三次.有没有更有效的方法来做到这一点?
请在下面找到一个简化的示例应用程序:注意:在此应用中,每个标签只能看到1个过滤器.通常它更像这样:
My_Filtered_Data[Species %in% input$filter1 &
x %in% input$x &
y %in% input$y &
z %in% input$z] #etc.
Run Code Online (Sandbox Code Playgroud)
我在看,reactiveValues
但无法真正找到它是如何工作的.原因我不想让它在1中reactive
是每次我更改其中一个工作表上的其中一个过滤器时,整个过滤过程再次启动,这非常耗时.我更希望有一个数据集只使用当时使用的过滤器进行更新.这就是我加入不同反应的原因
## app.R ##
library(shinydashboard)
library(data.table)
CustomHeader <- dashboardHeader(title='datatest')
iris<-iris
ui <- function(request) {
dashboardPage(
CustomHeader,
## Sidebar content
dashboardSidebar(
sidebarMenu(
menuItem("filter1 & Import", tabName = "filter1", icon = icon("dashboard")),
menuItem("filter2", tabName = "filter2", icon = icon("th")),
menuItem("filter3", tabName = "filter3", icon = icon("th"))
)
),
## Body content
dashboardBody(
tabItems(
# First tab content …
Run Code Online (Sandbox Code Playgroud) 我有一个如下所示的数据集:
set.seed(1234)
DT<-data.table(id=c(rep(c("a","b","c","d"),5)),
year=rep(seq(from = 2010.5,to=2012.5,by = .5),each=4),
value=rnorm(20,10,1))
DT
id year value
1: a 2010.5 8.792934
2: b 2010.5 10.277429
3: c 2010.5 11.084441
4: d 2010.5 7.654302
5: a 2011.0 10.429125
6: b 2011.0 10.506056
7: c 2011.0 9.425260
8: d 2011.0 9.453368
9: a 2011.5 9.435548
10: b 2011.5 9.109962
11: c 2011.5 9.522807
12: d 2011.5 9.001614
13: a 2012.0 9.223746
14: b 2012.0 10.064459
15: c 2012.0 10.959494
16: d 2012.0 9.889715
17: a 2012.5 …
Run Code Online (Sandbox Code Playgroud) 我无法弄清楚如何使用is.na(x)函数来表示R中的无限数字与数据表或每列显示有多少Inf:colSums(is.infinite(x))
我使用以下示例数据集:
DT <- data.table(a=c(1/0,1,2/0),b=c("a","b","c"),c=c(1/0,5,NA))
DT
a b c
1: Inf a Inf
2: 1 b 5
3: Inf c NA
colSums(is.na(DT))
a b c
0 0 1
colSums(is.infinite(DT))
Error in is.infinite(DT) : default method not implemented for type 'list'
DT[is.na(DT)] <- 100
DT
a b c
1: Inf a Inf
2: 1 b 5
3: Inf c 100
DT[is.infinite(DT)] <- 100
Error in is.infinite(DT) : default method not implemented for type 'list'
Run Code Online (Sandbox Code Playgroud)
我在这篇文章中发现如何用NA取代Inf,但我想说应该有更好的方法来实现这一点,例如is.infinite.我想看看每列的Inf,有关于此的任何想法吗?
非常感谢.BR蒂姆
我有一个大的data.table对象(1M行和220列),我想用NA替换所有空格('').我在这篇帖子中找到了一个解决方案,但是我的数据表速度非常慢(已超过15分钟)其他帖子的示例:
data = data.frame(cats=rep(c('', ' ', 'meow'),1e6),
dogs=rep(c("woof", " ", NA),1e6))
system.time(x<-apply(data, 2, function(x) gsub("^$|^ $", NA, x)))
Run Code Online (Sandbox Code Playgroud)
有没有更多的data.table快速实现这一目标的方法?
实际上,提供的数据与原始数据看起来不太像,只是举一个例子.我的实际数据的以下子集给出了CharToDate(x)错误:
DT <- data.table(ID=c(10),DEFAULT_DATE=as.Date("2012-07-31"),value='')
system.time(DT[DT=='']<-NA)
Run Code Online (Sandbox Code Playgroud) 由于这个问题,我想将 6 个highcharter
图表排成一行,就像这里一样。似乎在外面工作得很好flexdashboard
data(diamonds, package = "ggplot2")
diamonds <- diamonds[-6]
map(names(diamonds), function(x){
diamonds[[x]] %>%
hchart(showInLegend = FALSE) %>%
hc_add_theme(hc_theme_smpl()) %>%
hc_title(text = x) %>%
hc_yAxis(title = list(text = ""))
}) %>%
hw_grid(rowheight = 225, ncol = 3) %>% browsable()
Run Code Online (Sandbox Code Playgroud)
请在此处找到一个简单的示例,了解它如何在以下范围内不起作用flexdashboard
:
---
title: "test"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
---
```{r}
library(highcharter)
library(data.table)
library(ggplot2)
library(htmltools)
```
### trying to render with hw_grid
```{r}
sliderInput('ncol','ncol',min = 1,max=4,value = 2)
``` …
Run Code Online (Sandbox Code Playgroud) r ×11
shiny ×7
data.table ×5
na ×2
conditional ×1
css ×1
duplicates ×1
dygraphs ×1
filter ×1
htmlwidgets ×1
infinite ×1
lm ×1
lookup ×1
memory ×1
popup ×1
r-factor ×1
rcharts ×1
shinybs ×1