小编Mik*_*nen的帖子

如何组织大型闪亮应用程序?

组织更大的Shiny应用程序的最佳实践是什么?
我认为最好的R实践也适用于Shiny.
这里讨论最佳R实践:如何组织大型R程序
链接到谷歌的R风格指南:风格指南

但是,我可以采用什么样的Shiny上下文中的独特提示和技巧,使我的Shiny代码看起来更好(更具可读性)?我想的是:

  • 利用Shiny中的面向对象编程
  • server.R这部分应采购?
  • 包含markdown文档,图片,xml和源文件的项目的文件层次结构

例如,如果我正在使用,navbarPage并且tabsetPaneltabPanel添加几个UI元素后,我的每个代码都开始变得非常混乱.

示例代码:

server <- function(input, output) {

 #Here functions and outputs..

}

ui <- shinyUI(navbarPage("My Application",
  tabPanel("Component 1",
             sidebarLayout(
                sidebarPanel(
                    # UI elements..
                ),
                mainPanel(
                    tabsetPanel(
                        tabPanel("Plot", plotOutput("plot")
                                 # More UI elements..
                                 ), 
                        tabPanel("Summary", verbatimTextOutput("summary")
                                 # And some more...
                                 ), 
                        tabPanel("Table", tableOutput("table")
                                 # And...
                                 )
                    )
                )
    )           
  ),
  tabPanel("Component 2"),
  tabPanel("Component 3")
))

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

为了组织ui.R …

r shiny

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

sprintf无效格式'%d'

这有效:

> sprintf('%d', c(1, 1.5))
[1] "1" "1"
Run Code Online (Sandbox Code Playgroud)

这不是:

> sprintf('%d', c(1.5, 1))
Error in sprintf("%d", c(1.5, 1)) : 
  invalid format '%d'; use format %f, %e, %g or %a for numeric objects
Run Code Online (Sandbox Code Playgroud)

为什么?

c printf r coercion

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

闪亮的应用程序 actionButton 单击页面加载

我正在使用 navbarPage() 类型构建一个 Shiny 应用程序。我有三个选项卡 - 初始选项卡有一个 textInput() 框,其中定义了默认文本。该页面的 mainPanel() 有一个直方图和一个表格。在页面上加载这些更新并在基于该默认文本启动应用程序时反映正确的信息。

第二个选项卡应该显示基于该默认文本的 wordcloud。当我切换到该选项卡时出现错误 - 如果我返回第一个选项卡并输入新文本并点击 actionButton - wordcloud 将更新,但在我执行该操作之前不会更新。

有没有办法actionButton()在页面加载时进行提交或某种提交,以便带有 wordcloud 的选项卡可以更新?或者也许我只需要创建一个全局变量或其他东西。我不知道。我在这方面花了很多时间,但遇到了困难。任何帮助将不胜感激。

界面代码:

tabPanel("Word Cloud Diagram",
         fluidRow(
           sidebarPanel(
             width = 3,
             h5("The sentence input:"),
             wellPanel(span(h5(textOutput(
               'sent'
             )), style = "color:red")),
             sliderInput(
               "maxWC",
               h5("Maximum Number of Words:"),
               min = 10,
               max = 100,
               value = 50
             ),
             br(),
             #actionButton("update", "Update Word Cloud"),
             hr(),
             helpText(h5("Help Instruction:")),
             helpText(
               "Please have a try to make the prediction by using
               the dashboard on …
Run Code Online (Sandbox Code Playgroud)

r shiny shiny-server

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

Rmarkdown 演示幻灯片行情

我正在使用 rmarkdown 在 RStudio 中进行投影仪演示。我想在演示文稿的顶部获得幻灯片代码。德累斯顿主题应该支持那些行情德累斯顿 在此处输入图片说明

那么是否有可能通过使用 rmarkdown 来获取这些代码?当我编织 pdf 时,我得到的演示文稿没有幻灯片行情。

示例代码:

---
title: "Example"
output: beamer_presentation
theme: Dresden
---

# R Markdown

This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the …
Run Code Online (Sandbox Code Playgroud)

r rstudio r-markdown

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

根据匹配,时间,响应和分组信息,在R中为纵向数据添加新列.

示例数据由4列组成:

  • 响应
  • 时间
  • 比赛.

    在治疗组专栏中,有三种治疗方法:

  • treatment1
  • 控制
  • 对待2

    在响应列中,在给定时间内对每个ID有唯一的响应.时间显示在"时间"列中.在"匹配"列中有分组信息.不同的群体是:

  • GROUP_1
  • group_2

    所以每个治疗组(对照组,治疗组1 ......)也属于匹配组(group_1,group_2)

任务是根据"TreatmentGroup"列中的分组信息计算新列,并在"匹配"列中匹配信息.新列将包含treatmentX的响应变量 - 对该匹配组的控制.
例如:治疗2的反应 - 对照(1.2-1.8 = -0.6)和下一行1.4-2.0 = -0.6.因此,将治疗反应与给定时间(0或1)的对照反应进行比较.示例数据和结果表(手动计算):

   TreatmentGroup  ID Response Time   Match
1      treatment2 ID1      1.2    0 group_1
2      treatment2 ID1      1.4    1 group_1
3         control ID2      1.8    0 group_1
4         control ID2      2.0    1 group_1
5      treatment1 ID3      1.5    0 group_1
6      treatment1 ID3      1.8    1 group_1
7      treatment2 ID4      0.2    0 group_2
8      treatment2 ID4      0.3    1 group_2
9         control ID5 …
Run Code Online (Sandbox Code Playgroud)

statistics r dplyr

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

标签 统计

r ×5

shiny ×2

c ×1

coercion ×1

dplyr ×1

printf ×1

r-markdown ×1

rstudio ×1

shiny-server ×1

statistics ×1