小编Ign*_*cio的帖子

Shinydashboard变灰了downloadButton?

如何修复这个简单示例的下载按钮?

在此输入图像描述

library(shiny)
library(shinydashboard)
library(shinyjs)
header <- dashboardHeader()

sidebar <- dashboardSidebar(shinyjs::useShinyjs(),  
                            actionButton("start_proc", "Click to make download button appear"),
                            p(),
                            downloadButton('data_file', 'Download'))

body <- dashboardBody()

ui <- dashboardPage(header, sidebar, body)


server <- function(input, output) {

  observe({
    if (input$start_proc > 0) {
      Sys.sleep(1)
      # enable the download button
      shinyjs::show("data_file")
    }
  })

  output$data_file <- downloadHandler(
    filename = function() {
      paste('data-', Sys.Date(), '.csv', sep='')
    },
    content = function(file) {
      write.csv(data.frame(x=runif(5), y=rnorm(5)), file)
    }
  )
  # disable the downdload button on page load
  shinyjs::hide("data_file")
}

shinyApp(ui, …
Run Code Online (Sandbox Code Playgroud)

shiny shinydashboard shinyjs

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

添加popovers到闪亮的应用程序?

我想在窗口小部件的标题旁边添加一个(?),以便用户可以悬停或单击它并获取额外的信息和他们可以单击的链接.

这就是我现在所拥有的:

## app.R ##
library(shiny)
library(shinydashboard)
library(shinyBS)
# Header
header <- dashboardHeader()
# Sidebar
sidebar <- dashboardSidebar(fileInput("chosenfile", label = h4("File input"), 
                                      accept = ".csv"),
                            bsButton("q1", label = "", icon = icon("question"),
                                     style = "info", size = "extra-small"),
                            bsPopover(id = "q1", title = "Tidy data",
                                      content = paste0("You should read the ", 
                                                       a("tidy data paper", 
                                                         href = "http://vita.had.co.nz/papers/tidy-data.pdf",
                                                         target="_blank")),
                                      placement = "right", 
                                      trigger = "click", 
                                      options = list(container = "body")
                                      )
                            )
# Body
body <- dashboardBody()
# ui
ui …
Run Code Online (Sandbox Code Playgroud)

r twitter-bootstrap shiny shinybs

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

使用ggplot2重新整形数据以在R中绘图

我想用ggplot2绘制3行.我的数据看起来像这样

print(x)
     V1       V2       V3      V4
 1 -4800 25195.73 7415.219 7264.28
 2 -2800 15195.73 5415.219 7264.28
Run Code Online (Sandbox Code Playgroud)

从这个例子中,我强调我需要将我的数据重塑为这样的东西.是对的吗?

     id       x       y      
1     1     -4800   25195.73 
2     1     -2800   15195.73
3     2     -4800   7415.219
4     2     -2800   5415.219
5     3     -4800   7264.28
6     3     -2800   7264.28
Run Code Online (Sandbox Code Playgroud)

我该如何重塑?

谢谢!

plot r ggplot2 reshape

5
推荐指数
2
解决办法
3697
查看次数

使用纬度和经度转换为本地时区?

我有一个包含以下信息的数据集:纬度,经度,EST时间.例如,一次观察

lat = 13
long = -2
time1 = as.POSIXlt("2014-02-12 17:00:00", tz = "EST")
Run Code Online (Sandbox Code Playgroud)

我想创建一个新的变量timeL,即本地时间.有关如何使用R的任何建议吗?

谢谢!

timezone r

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

图表的闪亮rcharts大小?

我正在接近制作我想要的东西,但是现在我遇到了调整rChart输出的问题.现在我的输出位于我的第二列的左下角.我希望输出在第二列中居中,如果可能的话,可以调整大小以更好地适应它.

这是我的ui.R:

require(rCharts)
shinyUI(fluidPage(
  titlePanel("Quiz 3 grades distribution"),

  fluidRow(
    column(3,
      #helpText("Select grade in Quiz 1 before the treatment:"),    
      selectInput("select", label = h3("Grade Quiz 1 before the treatment:"), 
                  choices = list("All" = 0, "Not Perfect" = 1, "Perfect" = 2), 
                  selected = 0)
    ),

    column(9, showOutput("histogram","nvd3"), class = "span6")
  )
))
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

r shiny rcharts

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

拆分数据以与 R 尴尬地并行?

我有一个很大的 RDS 文件,我想使用 R 并行处理它。加载该文件时需要 7.3 GB 的内存。

如果我尝试使用多个内核,R 会因为内存不足而崩溃。有没有办法告诉 mclapply 使用共享内存而不是制作对象的副本?

这是我拥有的代码:

results <- readRDS('ResultsICC.RDS')

rand <- 0
Icc <- c(.5, 1, 1.5)
n <- c(.1, .5, 1)
phi <- c(0, .5, 1)
parameterSettings <- expand.grid(rand=rand, Icc=Icc, n=n, phi=phi)

rr <- list()
Ns <- results[[1]][[1]][[2]][,c('Country', 'n')]
EstimatedBestPFiveArmRaw <- matrix(NA, 26, 1000)
EstimatedBestP <- matrix(NA, 26, 1000)


outterloop <- function(dataIN){
  for(k in 1:1000){ #1000
    best <- dataIN[[k]][[2]]
    EstimatedBestPFiveArmRaw[,k] <- rep(weighted.mean(best$estimatedBestPFiveArmRaw, best$n), 26) 
    pHat <- dataIN[[k]][[3]]  
    best <- Ns
    best$estimatedBest <- …
Run Code Online (Sandbox Code Playgroud)

r mclapply

5
推荐指数
0
解决办法
285
查看次数

使用selectInput设置框标题?

我想使用selectInput在一个框上设置标题.例如,我希望默认标题为:名称2设置

现在,我能够获得冠军[1] "Name 2 settings".有没有办法删除[1]和引号?

谢谢!

这是我的示例应用:

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(dashboardHeader(),
                    dashboardSidebar(),
                    dashboardBody(fluidRow(
                      box(
                        title = "Settings", width = 6, solidHeader = TRUE, status = "primary",
                        flowLayout(selectInput(
                          "Design", "Design:",
                          c("Name 1" = "Name 1",
                            "Name 2" = "Name 2"),
                          selected = "Name 2"
                        ))
                      ),
                      box(
                        title = textOutput("Design"), width = 4, solidHeader = TRUE, status = "primary",
                        "Box content"
                      )
                    )))
server <- function(input, output) {
  output$Design <- renderPrint({
    paste(input$Design, 'settings') …
Run Code Online (Sandbox Code Playgroud)

shiny shinydashboard

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

vline左侧的阴影密度图?

是否可以使用 vline 作为截止点对密度图进行着色?例如:

df.plot <- data.frame(density=rnorm(100))
library(ggplot2)
ggplot(df.plot, aes(density)) + geom_density() + 
  geom_vline(xintercept = -0.25)
Run Code Online (Sandbox Code Playgroud)

我尝试创建一个新变量,但它没有按我预期的那样工作

df.plot <- df.plot %>% mutate(color=ifelse(density<(-0.25),"red","NULL"))


ggplot(df.plot, aes(density, fill = color, colour = color)) + geom_density() + 
  geom_vline(xintercept = -0.25)
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

R Markdown 和 Windows 中的多行乳胶方程

以下代码在 linux 上运行良好:

---
title: "LaTeX test"
author: "Ignacio"
output: html_document
---


## Latex

$$ 
\begin{aligned}

y_j \sim N(\theta_j , \sigma_j^2) \\

\sigma_j = \nu/\sqrt{n_j}   \\

\theta = \mu +\tau \times \eta \\

\eta \sim N(0,1) \\

\mu + \tau\times\eta = \theta \sim N(\mu , \tau^2)

\end{aligned}
$$
Run Code Online (Sandbox Code Playgroud)

在 Windows 上,rstudio 正确呈现方程:

在此处输入图片说明

但是,当我编织文件并使用 chrome 打开 HTML 时,或者即乳胶未正确呈现时:

在此处输入图片说明

有没有办法来解决这个问题?

r r-markdown

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

用所有列替换NA的负值?

假设我的数据看起来像这样(有更多列)

set.seed(112116)
df <- data.frame(x1 = sample(c(LETTERS, -1:-10), 100, replace = T),
                 x2 = sample(c(letters, -1:-10), 100, replace = T),
                 x3 = sample(c(1:30, -1:-10), 100, replace = T))
Run Code Online (Sandbox Code Playgroud)

我想用NA替换所有负数.我可以像这样一个接一个地做:

df <- df %>% mutate(x1 = replace(x1, which(x1<0), NA),
              x2 = replace(x2, which(x2<0), NA),
              x3 = replace(x3, which(x3<0), NA))
Run Code Online (Sandbox Code Playgroud)

但我希望有一种方法可以为我的数据中的所有列执行此操作

r dplyr

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