[英]How do I complete this code for Shiny App?
I am struggling in writing this shinyApp. 我正在努力编写此ShinyApp。 It's main aim is to investigate on the variables of a dataset.
其主要目的是研究数据集的变量。 First it produces the summary statistics on the selected variable.
首先,它生成所选变量的摘要统计信息。
In the second part; 在第二部分; I want this app to give me the pairplot of the varibles that I have selected in the checkbox in the UI.
我希望这个应用程序能给我在UI复选框中选择的变量对图。 I have used the dataset IRIS which is available to everyone, but I need the code to be adaptable to other datasets.
我使用了每个人都可以使用的数据集IRIS,但是我需要代码能够适应其他数据集。
Can someone please help me? 有人可以帮帮我吗?
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)
Maybe this little example can help you. 也许这个小例子可以帮助您。 It illustrates how to plot a normal R-Plot and a Plotly-Plot in a ShinyApp:
它说明了如何在ShinyApp中绘制普通R图和Plotly图:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.