【问题标题】:How do I complete this code for Shiny App?如何为 Shiny App 完成此代码?
【发布时间】:2019-05-20 08:43:04
【问题描述】:

我正在努力编写这个闪亮的应用程序。它的主要目的是研究数据集的变量。首先,它生成所选变量的汇总统计信息。

在第二部分;我希望这个应用程序为我提供我在 UI 的复选框中选择的变量的配对图。我使用了所有人都可以使用的数据集 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)

【问题讨论】:

  • 您的示例不起作用。仍然存在一些语法错误。 pairplot 来自哪个包?

标签: r shiny shiny-server shiny-reactivity


【解决方案1】:

也许这个小例子可以帮助你。它说明了如何在 ShinyApp 中绘制正常的 R-Plot 和 Plotly-Plot:

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)

【讨论】:

    猜你喜欢
    • 2021-04-16
    • 2012-12-23
    • 1970-01-01
    • 2016-01-03
    • 2014-09-16
    • 2018-08-30
    • 2015-09-16
    • 2010-11-16
    • 1970-01-01
    相关资源
    最近更新 更多