Как мне заполнить этот код для Shiny App? - PullRequest
0 голосов
/ 19 декабря 2018

Я изо всех сил пишу это блестящее приложение.Его главная цель - исследовать переменные набора данных.Сначала он генерирует сводную статистику по выбранной переменной.

Во второй части;Я хочу, чтобы это приложение давало мне пару переменных, которые я выбрал в флажке в пользовательском интерфейсе.Я использовал набор данных IRIS, который доступен каждому, но мне нужен код, который можно адаптировать к другим наборам данных.

Может кто-нибудь помочь мне?

library(shiny)
library(plotly)

data(iris)

ui<-fluidPage(
  titlePanel("Iris"),
  sidebarLayout(
    sidebarPanel(
      selectInput("var",label="Choose a variable",
                  choice=list("Sepal.Length"=1, "Sepal.Width"=2, "Petal.Length"=3, "Petal.Width"=4, "Species"=5), selectize=FALSE),
      checkboxGroupInput(inputId ="independent",label = "Select independent variables", choices = names(iris)),

      mainPanel(
        verbatimTextOutput("sum"),
        plotlyOutput('plot_id_in_ui ', height = "900px")
      )
    ))
)

server<-function(input,output){
  output$sum <- renderPrint({

    summary(iris[, as.numeric(input$var)])
  })
  output$plot_id_in_ui <- renderplot( { "DON'T KNOW HOW TO WRITE THIS PART"

    pairplot(iris, varnames, type = "both", penalty.par.val = "lambda.1se",

             nvals = c(20, 20), pred.type = "response") } )

})

shinyApp(ui, server)

1 Ответ

0 голосов
/ 20 декабря 2018

Может быть, этот маленький пример поможет вам.Он иллюстрирует, как построить нормальный R-график и Plotly-график в ShinyApp:

library(shiny)
library(plotly)

ui <- fluidPage(
  titlePanel("Iris"),
  sidebarLayout(
    sidebarPanel(
      selectInput("var",label="Choose a variable",
                  choice=list("Sepal.Length"=1, "Sepal.Width"=2, "Petal.Length"=3, "Petal.Width"=4, "Species"=5), selectize=FALSE),
      checkboxGroupInput(inputId ="independent",label = "Select independent variables", choices = names(iris))
      ),
    mainPanel(
      verbatimTextOutput("sum"),
      plotOutput("plot"),
      plotlyOutput("plotly")
    )
  )
)

server <- function(input,output) {

  output$sum <- renderPrint({  
    summary(iris[, as.numeric(input$var)])
  })

  output$plot <- renderPlot({
    plot(iris)
  })

  output$plotly <- renderPlotly({
    plot_ly(iris) %>% 
      add_trace(x=iris$Sepal.Length, y=iris$Sepal.Width, type="scatter", mode="markers")
  })

}

shinyApp(ui, server)
...