小编Rus*_*ian的帖子

如何将图像放在R Shiny标题中

所以我使用的是R Shiny,我想在标题的文本右侧放置一个图像.我似乎可以将图像放在应用程序的任何位置,但标题旁边除外.你能不把图像放在titlePanel()功能中吗?这是我正在使用的代码片段:

library(shiny)

# Define UI for random distribution application 
shinyUI(fluidPage(#theme="bootstrap.css",

  # Application title
  titlePanel("My Title",img(src = "picture.jpg", height = 50, width = 100)),
  sidebarLayout(
    sidebarPanel(
Run Code Online (Sandbox Code Playgroud)

因此,当我使用上面的代码时,我似乎无法在应用程序的任何位置看到我的图像....

r shiny

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

循环次序对R的速度是否重要

我有一个问题,我想进行模拟研究,模拟取决于两个变量xy. x并且y是我想要在我的模拟研究中评估的潜在值的向量(如此不同的组合).此外,对于每个组合xy我想多次重复(因为在那里一个随机期限和的每次运行xy将变化).

举一个我正在处理的例子,我有以下简化的例子:

x = 1:10
y = 11:20

iterations = 2000
iter = 1

solution = array(NA,c(length(x),3,iterations))
for(i in x){
    for(j in y){
        for(k in 1:iterations){ 
            z = rnorm(3) + c(i,j,1) 
            solution[i,,k] = z
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是在我的实际问题中,在for循环中得到的代码要评估的重要性要小得多.但是,输入结构和输出结构相同.

所以我想知道,比如使用上面的例子,最有效的方法是按顺序设置循环,或者最好让它k in 1:iterations成为最外层的循环并尝试outer()在该循环中使用某种命令我将z在网格上评估函数(在这个例子中)xy

此外,我对完全不同的设置和设计非常开放.在一天结束时,我希望能够获得一个基于一个解决方案x,并y与平均超过所有的迭代,即apply(solution, c(1,2),mean)


编辑:

正如我所建议的,这是我正在使用的实际代码.

library(survival)

iter = 2000 …
Run Code Online (Sandbox Code Playgroud)

r

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

R Shiny 应用程序可保存输入以供以后使用

我正在编写一个闪亮的应用程序,它将有许多用户输入,因此我希望有一个选项,允许用户保存他们的输入并将其加载回来以供以后使用。我能够按照我在网上找到的示例来执行此操作,但现在我想寻求一些更改代码功能的帮助。这是代码:

\n\n
library(shiny)  \n\nui <- shinyUI(fluidPage(\n  br(),\n\n  actionButton("load_inputs", "Load inputs"),\n  br(),\n  br(),\n\n  numericInput("n", "Number",min = 1, value = 5),\n  numericInput("upper", "Upper",min = 0, max = 100, value = 15),\n  numericInput("lower", "Lower",min = 0, max = 100, value = 5),\n\n  actionButton(\'save_inputs\', \'Save inputs\')\n\n)) \n\nserver <-  shinyServer(function(input, output,session) { \n\n  switch(Sys.info()[[\'sysname\']],\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 Windows= {setwd(file.path(Sys.getenv("USERPROFILE"),"Desktop",fsep="\\\\"))},\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 Mac = { \xc2\xa0setwd("~/Desktop/")})\n\n  observeEvent(input$load_inputs,{   \n\n    if(!file.exists(\'inputs.RDS\')) {return(NULL)}\n\n    savedInputs <- readRDS(\'inputs.RDS\')\n\n    inputIDs      <- names(savedInputs) \n    inputvalues   <- unlist(savedInputs) \n    for (i in 1:length(savedInputs)) …
Run Code Online (Sandbox Code Playgroud)

r shiny

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

阅读R Shiny中的文件

所以我在R shiny中构建一个应用程序,要求用户上传.csv文件.一旦R shine读入,我不确定如何实际操作该对象使用.一般代码语法如下:

UI文件:

#ui.R
# Define UI for random distribution application 
shinyUI(fluidPage(

  # Application title
  titlePanel("ORR Simulator"),

  # Sidebar with controls to select the random distribution type
  # and number of observations to generate. Note the use of the
  # br() element to introduce extra vertical spacing
  sidebarLayout(
    sidebarPanel(
          fileInput('file1', 'Select the XXX.csv file',
                accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
      tags$hr(),
          fileInput('file2', 'Select the YYY.csv file',
                accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
      tags$hr(),
     numericInput("S", "Number of simulations to run:", 100),

       mainPanel(
plotOutput("plot")
    )
  )
))
Run Code Online (Sandbox Code Playgroud)

服务器文件:

#server.R
library(shiny)

shinyServer(function(input, …
Run Code Online (Sandbox Code Playgroud)

r shiny

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

如何让 Shiny 等到你点击提交

所以我正在构建一个运行模拟研究的 R Shinny 应用程序,所以每次用户更改其中一个输入时,我不希望应用程序开始运行模拟,直到他们点击提交按钮。我怎样才能做到这一点?

这是我到目前为止的代码:

The UI file:

#ui.R
# Define UI for random distribution application 
shinyUI(fluidPage(

  # Application title
  titlePanel("ORR Simulator"),

  # Sidebar with controls to select the random distribution type
  # and number of observations to generate. Note the use of the
  # br() element to introduce extra vertical spacing
  sidebarLayout(
    sidebarPanel(
          fileInput('file1', 'Select the XXX.csv file',
                accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
      tags$hr(),
          fileInput('file2', 'Select the YYY.csv file',
                accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
      tags$hr(),
     numericInput("S", "Number of simulations to run:", 100),

       mainPanel(
plotOutput("plot")
    )
  )
)) …
Run Code Online (Sandbox Code Playgroud)

r shiny

4
推荐指数
2
解决办法
4425
查看次数

R闪亮动态输入

我想构建一个R闪亮的应用程序,它具有动态输入,要求用户输入数字,然后根据该输入生成4个输入字段.这就是我的想法.

library(shiny)

# Define UI for random distribution application 
shinyUI(fluidPage(

  # Application title
  titlePanel("Calcs"),

  # Sidebar with controls to select the random distribution type
  # and number of observations to generate. Note the use of the
  # br() element to introduce extra vertical spacing
  sidebarLayout(
    sidebarPanel(
     numericInput("dorr", "How many inputs do you want",4),
     i = i+1
     while(input$dorr<i){
      numericInput("S", "Number of simulations to run:", 10)
      i=i+1
     }
     numericInput("S", "Number of simulations to run:", 10),
     actionButton(inputId = "submit_loc",label = "Run the Simulation") …
Run Code Online (Sandbox Code Playgroud)

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

R帮助手册中有乳胶数学吗?

我正在开发一个R软件包,我正在使用该软件包Roxygen2为我的R函数编写帮助手册.我想知道的是,如果可以在手册页中使用乳胶作为数学公式吗?

例如,如果我有一个调用的函数add2,它执行以下操作:

add2 = function(x,y){
       z = x+y
       return(z)
}
Run Code Online (Sandbox Code Playgroud)

使用Roxygen2文档我有以下内容:

##' @include add2.R
{}

##' Compute the sum of x_1 and x_2
##'
##' Computes the sum of x_1 and x_2
##'
##' @param x_1 number of guys
##' @param x_2 number of girls
##' @return The sum of the two values x_1 and x_2
##'
##' @example examples/adding.R
##' @export
##' @author Name
Run Code Online (Sandbox Code Playgroud)

这对我有用,但是在帮助手册中显示x1和x2为x_1和x_2,而我希望它看起来像乳胶数学,实际上有x上的下标,即$ x_1 $和$ x_2 $ …

latex r roxygen2

4
推荐指数
2
解决办法
1018
查看次数

如何在 Shiny 中放置按钮

我正在构建一个闪亮的应用程序,其中将是一个带有三个选项卡(tab1、tab2 和 tab3)的 tabsetPanel。我将有两个适用于所有选项卡的操作按钮,但我不希望选项卡内的操作按钮,我希望它们位于选项卡的最右侧,所以现在无论您在哪个选项卡中,您始终可以看到操作按钮。这是我正在谈论的一些代码:

tabsetPanel(

        tabPanel(
           title = "Tab1"
        )

        tabPanel(
           title = "Tab2"
        )

        tabPanel(
           title = "Tab3"
        )
)
Run Code Online (Sandbox Code Playgroud)

所以我希望这两个操作按钮位于选项卡的最右侧但位于 tabsetPanel 之外。

actionButton('load_inputs', 'Load inputs')
actionButton('save_inputs', 'Save inputs')
Run Code Online (Sandbox Code Playgroud)

如果有一种方法可以在actionButton()函数内指定您希望按钮出现的位置,那就太好了。

r shiny

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

在Shiny中禁用按钮

我正在编写一些Shiny代码,用户将在该应用程序中输入一些输入,然后单击一个操作按钮.操作按钮会触发一系列模拟运行需要很长时间,所以我想在单击操作按钮后将其禁用,以便用户在模拟运行之前无法一直点击它.我遇到了这些shinyjs::enableshinyjs::disable功能,但一直很难利用它们.这是我的服务器代码:

output$button1= renderUI({
        if(input$Button1 > 0)  {
          shinyjs::disable("Button1")
                tableOutput("table")
          shinyjs::enable("Button1")}
  })
Run Code Online (Sandbox Code Playgroud)

但是,当我使用此代码时,单击操作按钮没有任何反应.即,操作按钮不会变灰,也不会生成表格.但是,当我带走shinyjs::enable()命令时,即,

    output$button1= renderUI({
            if(input$Button1 > 0)  {
              shinyjs::disable("Button1")
                    tableOutput("table")
}
      })
Run Code Online (Sandbox Code Playgroud)

首先生成表格,然后按钮变为灰色,但我希望按钮变为灰色,然后表格生成自己.

我在这做错了什么?


这是我根据Geovany的建议更新的代码,但它仍然不适合我

Button1Ready <- reactiveValues(ok = FALSE)

        observeEvent(input$Button1,  {
          shinyjs::disable("Button1")
          RunButton1Ready$ok <- FALSE
          RunButton1Ready$ok <- TRUE
  })

output$SumUI1= renderUI({
        if(Button1Ready$ok){
          tableOutput("table")
          shinyjs::enable("Button1")
        }
})
Run Code Online (Sandbox Code Playgroud)

在哪里澄清我还:

output$table <- renderTable({

#My code....

)}
Run Code Online (Sandbox Code Playgroud)

r shiny

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

在 Shiny 中摆脱文件上传中的状态栏

我正在使用 R Shiny,我的应用程序构建为从用户读取文件以供稍后操作。我想尝试使用该fileInput()命令,但我不想看到浏览选项旁边的加载栏。有没有办法摆脱它或隐藏它,使它看起来像一个按钮?另外,我可以将默认的“浏览”重命名为其他名称,例如“加载”吗?

或者,我想我会对有一个被按下然后调用inputFile()命令的操作按钮感兴趣,但我很难实现它。

最终目标是我希望用户能够按下一个表示加载的按钮,然后这会触发某种弹出窗口,允许用户上传文件,但我只想看到一个按钮输入的首页。

file-upload r shiny

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

标签 统计

r ×9

shiny ×7

file-upload ×1

latex ×1

roxygen2 ×1