Skip to content

Instantly share code, notes, and snippets.

@bdemeshev
Last active March 21, 2019 18:47
Show Gist options
  • Save bdemeshev/43d574df0f704f979eaf to your computer and use it in GitHub Desktop.
Save bdemeshev/43d574df0f704f979eaf to your computer and use it in GitHub Desktop.
[Простой пример shiny] #R #code #shiny
library("mvtnorm") # для многомерного нормального
library("ggplot2") # для графиков
n_obs <- 100
corr <- 0.5
mu <- c(10, 15)
# ковариационная матрица
# 4 corr * 2 * 3
# ? 9
A <- matrix(
c(4, corr*6, corr*6, 9),
nrow = 2)
X <- rmvnorm(n_obs, mean = mu, sigma = A)
X
# goo.gl/Lxd4yL
qplot(X[, 2])
qplot(x = X[, 1], y = X[, 2])
library("mvtnorm") # для многомерного нормального
library("ggplot2") # для графиков
shinyServer( function(input, output) {
update_x <- reactive({
mu <- c(10, 15)
A <- matrix(
c(4, input$corr*6, input$corr*6, 9), nrow = 2)
X <- rmvnorm(input$n_obs, mean = mu, sigma = A)
X
})
output$histogram <- renderPlot({
X <- update_x()
qplot(X[, 2])
})
output$dotplot <- renderPlot({
X <- update_x()
qplot(x = X[, 1], y = X[, 2])
})
})
library("shiny")
shinyUI(pageWithSidebar(
headerPanel("Винни-Пух и многомерное нормальное"),
sidebarPanel(
sliderInput("n_obs", "Количество наблюдений",
min = 50, max = 500, step = 10, value = 100,
animate = TRUE),
sliderInput("corr", "Привет Таисии от Корреляции",
min = -1, max = 1, step = 0.1, value = 0.5,
animate = TRUE)
),
mainPanel(
plotOutput("histogram"),
plotOutput("dotplot")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment