Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:每次定制都需要一致的随机样本_R_Shiny_Random Sample - Fatal编程技术网

R:每次定制都需要一致的随机样本

R:每次定制都需要一致的随机样本,r,shiny,random-sample,R,Shiny,Random Sample,这是我的第一个问题,如果我不遵守任何网站规范,请提前道歉 我在用R做实验。我正在尝试制作一个应用程序,允许用户自定义不同分布和内核估计器的许多组件。然而,在我进一步讨论之前,我的问题是:每次我调整应用程序中的一个滑块或其他可自定义选项时,都会绘制一个全新的示例。例如,如果我想减少内核带宽,如何使用一个示例而不进行更改? 现在我有以下ui.R和server.R代码: library(shiny) shinyUI(bootstrapPage( headerPanel("K

这是我的第一个问题,如果我不遵守任何网站规范,请提前道歉

我在用R做实验。我正在尝试制作一个应用程序,允许用户自定义不同分布和内核估计器的许多组件。然而,在我进一步讨论之前,我的问题是:每次我调整应用程序中的一个滑块或其他可自定义选项时,都会绘制一个全新的示例。例如,如果我想减少内核带宽,如何使用一个示例而不进行更改?

现在我有以下
ui.R
server.R
代码:

    library(shiny)
    shinyUI(bootstrapPage(
      headerPanel("Kernel Estimation"),
      mainPanel(
      sliderInput(inputId = "n_breaks",
          label = "Number of bins in histogram (approximate):",
          min = 1,
          max = 50,
          value = 25),

      sliderInput(inputId = "observations",
         label = "Number of observations:",
         min = 10,
         max = 1000,
         value = 500),

      checkboxInput(inputId = "density",
            label = strong("Show density estimate"),
            value = FALSE),

      # Display this only if the density is shown
      conditionalPanel(condition = "input.density == true",
               sliderInput(inputId = "bw_adjust",
                           label = "Bandwidth adjustment:",
                           min = 0.2, max = 2, value = 1, step = 0.2)),

      conditionalPanel(condition = "input.density == true",
               selectInput(inputId = "kernel",
                           label = "Type of Kernel:",
                           list("Gaussian" = "gaussian", "Epanechnikov" = "epanechnikov", "Rectangular" = "rectangular", "Triangular" = "triangular", "Biweight" = "biweight", "Optcosine" = "optcosine"))),

      checkboxInput(inputId = "individual_obs",
            label = strong("Show individual observations"),
            value = FALSE),

      plotOutput(outputId = "main_plot", height = "300px")

    )))
AAAA和:

    library(shiny)

    shinyServer(function(input, output) {

      output$main_plot <- renderPlot({
        hist(rnorm(input$observations,mean=0,sd=1),
     probability = TRUE,
     breaks = as.numeric(input$n_breaks),
     xlab = "Observations",
     main = "Standard Normal Distribution")

if (input$individual_obs) {
  rug(rnorm(input$observations,mean=0,sd=1), col = "red")
}

if (input$density) {
  dens <- density(rnorm(input$observations,mean=0,sd=1),
                  kernel = input$kernel,
                  adjust = input$bw_adjust)
  lines(dens, col = "blue")
}

      })
    })
库(闪亮)
shinyServer(功能(输入、输出){

输出$main_plot我认为您的问题可以通过以下反应函数生成分布来解决:

get_observations <- reactive(
{
    return(rnorm(input$observations,mean=0,sd=1))
})

if (input$individual_obs) {
  rug(get_observations(), col = "red")
}

if (input$density) {
  dens <- density(get_observations(),
                  kernel = input$kernel,
                  adjust = input$bw_adjust)
  lines(dens, col = "blue")
}

get_observations我认为你的问题可以通过在反应函数中生成分布来解决,如下所示:

get_observations <- reactive(
{
    return(rnorm(input$observations,mean=0,sd=1))
})

if (input$individual_obs) {
  rug(get_observations(), col = "red")
}

if (input$density) {
  dens <- density(get_observations(),
                  kernel = input$kernel,
                  adjust = input$bw_adjust)
  lines(dens, col = "blue")
}

get_observations我认为你的问题可以通过在反应函数中生成分布来解决,如下所示:

get_observations <- reactive(
{
    return(rnorm(input$observations,mean=0,sd=1))
})

if (input$individual_obs) {
  rug(get_observations(), col = "red")
}

if (input$density) {
  dens <- density(get_observations(),
                  kernel = input$kernel,
                  adjust = input$bw_adjust)
  lines(dens, col = "blue")
}

get_observations我认为你的问题可以通过在反应函数中生成分布来解决,如下所示:

get_observations <- reactive(
{
    return(rnorm(input$observations,mean=0,sd=1))
})

if (input$individual_obs) {
  rug(get_observations(), col = "red")
}

if (input$density) {
  dens <- density(get_observations(),
                  kernel = input$kernel,
                  adjust = input$bw_adjust)
  lines(dens, col = "blue")
}

get\u查看
set.seed
的帮助文件。查看
set.seed
的帮助文件。查看
set.seed
的帮助文件。查看
set.seed
的帮助文件。这绝对是我所需要的-非常感谢!这似乎是我需要知道的许多闪亮应用程序的那种东西,所以我很高兴这是一个好的选择简单修复(:这绝对是我所需要的-非常感谢!这似乎是我需要知道的关于很多闪亮应用的事情,所以我很高兴这是一个简单的修复(:这绝对是我需要的-非常感谢!这似乎是我需要知道的关于很多闪亮应用的事情,所以我很高兴这是一个简单的修复(:这绝对是我所需要的-非常感谢!对于很多闪亮的应用程序,这似乎是我需要知道的事情,所以我很高兴这是一个简单的修复(: