Hi everybody!
I am trying to start using plotly with shiny, but unfortunately it doesn’t work with my code. As an example I wrote this (sorry that descriptions in UI part are in russian):
UI:
library(shiny)
library(ggplot2)
library(plotly)
library(mvtnorm)
shinyUI(fluidPage(
titlePanel("Грачев Влад инкорпорейшн"),
sidebarLayout(
sidebarPanel(
sliderInput('n_obs', 'Количество испытаний', min = 0, max = 1000, value = 500, animate = TRUE),
sliderInput('prc', 'Средний рост детей', min = 170, max = 180, value = 175, step = 0.5, animate = TRUE),
sliderInput('prp', 'Средний рост родителей', min = 170, max = 180, value = 175, step = 0.5, animate = TRUE),
sliderInput('corr', 'Корреляция между ростом ребенка и ростом родителей', min = -1, max = 1, value = 0.5, step = 0.1, animate = TRUE),
sliderInput('stdc', 'Стандартное отклонение роста детей', min = 0, max = 1, value = 0.5, animate = TRUE),
sliderInput('stdp', 'Стандартное отклонение роста родителей', min = 0, max = 1, value = 0.5, animate = TRUE)
),
mainPanel(
plotOutput('dotplot'),
plotOutput('plotl')
)
)
))
Server:
shinyServer(function(input, output){
update_x <- reactive({
mu <- c(input$prc,input$prp)
A <-matrix(
c(input$stdc, input$corr*sqrt(input$stdc*input$stdp), input$corr*sqrt(input$stdc*input$stdp), input$stdp),
nrow = 2
)
X <- rmvnorm(input$n_obs, mean = mu, sigma = A)
X
})
output$dotplot <- renderPlot({
X <- data.frame(update_x())
g <- ggplot(X, aes(x=X[,1], y = X[,2])) + geom_jitter() + stat_smooth()
gg <- ggplotly(g)
gg
})
output$plotl <- renderPlotly({
X <- data.frame(update_x())
g <-ggplot(X, aes(X[,2])) + geom_histogram(binwidth = 0.2)
gg <- ggplotly(g)
gg
})
})
It works without plotly (just ordinary renderPlot and ggplot graph):
But when i am starting the code above it doesn’t show any graphs or warnings (only empty space) and there are 2 warnings in the console: Using size for a discrete variable is not advised.
Thanks in advance
Vlad