小编tho*_*hal的帖子

在shinydashboard中调整dashboardheader的高度

我想知道如何调整dashboardheaderin的高度shinydashboard

dashboardHeader(
    title = loadingLogo('http://company.fr/','logo.jpg','buffpowa.gif'),
    titleWidth = 600
) 
Run Code Online (Sandbox Code Playgroud)

我可以修改,width但标志对于标题来说太大了。我希望标题有足够的高度来显示完整的标志。

谢谢

r shiny shinydashboard

4
推荐指数
1
解决办法
5321
查看次数

使用 do 时保留列

代码

假设我有以下代码(我知道,而不是第二个domutate在这种情况下我可以使用一个简单的(并跳过rowwise()),但这不是重点,因为在我的实际代码中,第二do个更复杂一些并且计算一个模型):

library(dplyr)
set.seed(1)
d <- data_frame(n = c(5, 1, 3))
e <- d %>% group_by(n) %>% 
    do(data_frame(y = rnorm(.$n), dat = list(data.frame(a = 1)))) 
e %>% rowwise() %>% do(data_frame(sum = .$y + .$n))

# Source: local data frame [9 x 1]
# Groups: <by row>

# # A tibble: 9 x 1
#         sum
# *     <dbl>
# 1 0.3735462
# 2 3.1836433
# 3 2.1643714
# 4 4.5952808
# 5 …
Run Code Online (Sandbox Code Playgroud)

r dplyr

4
推荐指数
1
解决办法
216
查看次数

purrr :: map相当于dplyr :: do

阅读https://twitter.com/hadleywickham/status/719542847045636096我明白这种purrr方法基本上应该取代do.

因此,我想知道如何使用purrr它:

library(dplyr)
d <- data_frame(n = 1:3)
d %>% rowwise() %>% do(data_frame(x = seq_len(.$n))) %>% ungroup()
# # tibble [6 x 1]
#       x
# * <int>
# 1     1
# 2     1
# 3     2
# 4     1
# 5     2
# 6     3
Run Code Online (Sandbox Code Playgroud)

我能得到的最接近的是:

library(purrrr)
d %>% mutate(x = map(n, seq_len))
# # A tibble: 3 x 2
#       n         x
#   <int>    <list>
# 1     1 <int [1]> …
Run Code Online (Sandbox Code Playgroud)

r dplyr purrr

4
推荐指数
1
解决办法
332
查看次数

确定ggplot是否有图例

如果任何给定的ggplot对象有图例,我怎么能以编程方式找出?我正在考虑转换到grob第一个,并检查guide-box布局中是否有一个,但感觉有点hackish.有关如何以可靠和可重复的方式做到这一点的任何建议?

library(ggplot2)
library(grid)
bp <- ggplot(iris, aes(Petal.Length, Petal.Width)) + theme(legend.position = "top")
noLegend <- bp + geom_point()
withLegend <- bp + geom_point(aes(color = Species))
gNoLegend <- ggplotGrob(noLegend)
gWithLegend <- ggplotGrob(withLegend)

any(gNoLegend$layout$name == "guide-box")
# [1] FALSE
any(gWithLegend$layout$name == "guide-box")
# [1] TRUE
Run Code Online (Sandbox Code Playgroud)

r ggplot2

3
推荐指数
1
解决办法
64
查看次数

在 textInput 中选择文本/设置焦点

背景

在我的应用程序中,我有一个登录页面,其中一个textInput用于用户名,一个passwordInput用于密码,一个actionButton用于提交。如果密码/用户名无法识别,我会显示一条错误消息。到目前为止,一切都很好。textInput如果登录不起作用,我现在只想以编程方式选择/突出显示用户名中的所有文本。

问题

如何选择用户名输入表单中的文本?我查看了updateTextInput,但这样我只能更改值,而不能更改选择。我需要回退到 JavaScript 吗?

代码

library(shiny)

is_valid_user <- function(uid, pwd) {
   FALSE
}

ui <- fluidPage(
   textInput("uid", "Username:"),
   passwordInput("pwd", "Password"),
   actionButton("ok", "Login"),
   div(textOutput("error"))
)

server <- function(input, output, session) {
    observeEvent(input$ok, {
                 if (!is_valid_user(req(input$uid), req(input$pwd))) {
                    output$error <- renderText("Username/password incorrect!")
                    ## TODO: select all text in textInput("uid"), but HOW?
                 }})
}

shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

r shiny

3
推荐指数
1
解决办法
773
查看次数

当没有文件上传到shiny app时使用默认的csv文件

我有一个闪亮的应用程序,用户上传两个 csv 文件 - 一个参考数据集和一个测试数据集。数据集在服务器代码中的反应式表达式中进行操作,然后使用其输出来生成表格和图表。

如果没有上传参考数据集,我想使用默认参考数据集。如果没有上传数据,如何让反应式表达式返回默认数据?

我尝试在应用程序开头加载数据(将其称为“default.ref.data”,然后在服务器代码中使用以下内容:

ref.data=reactive({
   req(input$ref.upload)
   # read the data frame that has been uploaded
   df.ref1 <- read.csv(input$ref.upload$datapath) 

   #do some stuff

   return(df.ref1)
   if(is.null(input$files)) return(default.ref.data)
})
Run Code Online (Sandbox Code Playgroud)

最后一行的目的是在没有上传输入文件的情况下返回我之前读入的默认文件。这是行不通的。我应该做什么?我应该从不同的角度来看待它吗?

r shiny

3
推荐指数
1
解决办法
1306
查看次数

在一个图中将ggplot2对象与晶格对象组合在一起

我想结合ggplot2一个lattice情节对象.由于两个包都是基于grid我想知道这是否可能?理想情况下,我会做所有事情,ggplot2但我无法绘制三维散点图.

假设我有以下数据:

set.seed(1)
mdat <- data.frame(x = rnorm(100), y = rnorm(100), z = rnorm(100),
                   cluster = factor(sample(5, 100, TRUE)))
Run Code Online (Sandbox Code Playgroud)

首先,我想在以下位置创建一个散点图矩阵ggplot2:

library(ggplot2)
library(gtools)
library(plyr)

cols <- c("x", "y", "z")
allS <- adply(combinations(3, 2, cols), 1, function(r)
    data.frame(cluster = mdat$cluster,
          var.x = r[1],
          x = mdat[[r[1]]],
          var.y = r[2],
          y = mdat[[r[2]]]))

sc <- ggplot(allS, aes(x = x, y = y, color = cluster)) + geom_point() +
      facet_grid(var.x ~ var.y)
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.现在我想创建一个lattice …

r ggplot2 lattice

2
推荐指数
1
解决办法
636
查看次数

在数据框中,我想比较A列和B列,并提取其中A&gt; = B?

Cars         A      B
Honda        5      3     
Kia          7      5
BMW          4      8
Mazda        6      10
Hyundai      15     12
Lexus        22     19
Toyota       40     50
Jeep         60     50
Run Code Online (Sandbox Code Playgroud)

上图是我的数据框。据此,我想将A列与B列进行比较,并提取A中大于或等于B的值(A> = B)。

我试图通过使用函数来解决这个问题

pmax(Cars$A,Cars$B)

但这给了我这个结果-5,7,8,10,15,22,50,60

我想要的结果-5,7,15,22,60

r dataframe

2
推荐指数
1
解决办法
64
查看次数

Shinydashboard::box 中的 splitLayout

目标

我想在actionButtonaselectInput的页脚中放置 a旁边shinydashboard::box。根据this SO question splitLayout应该做我想做的。

问题

selectInput没有填满整个空间,投入页脚时。似乎一旦在页脚中,selectInput总是采用固定的宽度。有趣的是,当将相同的元素放入框体时,控件会按预期呈现。

我如何管理它selectInputactionButton

  1. 彼此相邻并且
  2. 跨越整条线?

代码

library(shiny)
library(shinydashboard)

boxUI <- function(width) {
  box(
    splitLayout(
      selectInput("x", NULL, paste(strrep("x", 10), 1:10)),
      actionButton("ok", icon("trash")),
      cellWidths = c("85%", "15%"),
      cellArgs = list(style = "vertical-align: top")),
    footer = splitLayout(
      selectInput("y", NULL, paste(strrep("x", 10), 1:10)),
      actionButton("ok", icon("trash")),
      cellWidths = c("85%", "15%"),
      cellArgs = list(style = "vertical-align: top")
    ), width = width, solidHeader = TRUE, …
Run Code Online (Sandbox Code Playgroud)

r shiny shinydashboard

1
推荐指数
1
解决办法
1122
查看次数

如何将嵌套 df 内的变量中出现次数少于 k 次的所有值设置为 0

library(tidyverse)
ex <- structure(list(group = c("Group A", "Group B", "Group C"), data = list(
structure(list(a = c(25.1, 15.1, 28.7, 29.7, 5.3, 3.4, 5.3, 
10.1, 2.4, 18, 4.7, 22.1, 9.5, 3.1, 26.5, 5.1, 24, 22.5, 
19.4, 22.9, 24.5, 18.2, 7.9, 5.3, 24.7), b = c(95.1, 51, 
100, 94.1, 47.3, 0, 50.7, 45.8, 40.7, 49.4, 51.9, 76.4, 26.7, 
19.8, 37.4, 59.4, 59.1, 60.2, 26.1, 2.8, 100, 40.7, 56.4, 
42.5, 0), c = c(39.9, 42.7, 16.3, 11.1, 56.9, 17.8, 62, 28.1, 
43, 44.8, …
Run Code Online (Sandbox Code Playgroud)

r dplyr purrr

1
推荐指数
1
解决办法
85
查看次数

标签 统计

r ×10

shiny ×4

dplyr ×3

ggplot2 ×2

purrr ×2

shinydashboard ×2

dataframe ×1

lattice ×1