r - 如何为 Shiny App 完成此代码?
问题描述
我正在努力编写这个闪亮的应用程序。它的主要目的是研究数据集的变量。首先,它生成所选变量的汇总统计信息。
在第二部分;我希望这个应用程序给我我在 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)
解决方案
也许这个小例子可以帮助你。它说明了如何在 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)
推荐阅读
- python - 使用注释#'s 作为装饰以获得更好的视觉识别 - 这是不好的做法吗?
- python - TensorFlow 初始化给出了所有的
- mysql - SSMS SQL - 将表中的一行与上一行进行比较 - 状态更改
- css - Safari - “输入搜索”导致视口向左推
- cas - CAS 5.3.1 和随机 404
- ios - 如何使用 UISlider 更新 UIView 宽度?
- reactjs - React-navigation:在 switch navigator 中嵌套堆栈导航器和选项卡导航器会产生 2 个标题
- sql - 检索 PostgreSQL 中日期范围内的记录
- python - 通过泰勒展开估计 pi 的错误
- julia - 在 Julia 中将标记形状提供为 Int