r - 单个闪亮应用程序中不同变量的散点图
问题描述
我使用 R shiny 为单个应用程序中不同变量的散点图创建多个选项卡。我的代码看起来没问题,但错误提示我没有“定义我的主面板”。有人可以帮助我哪里出错,或者如果我的整个方法不准确,请在这里输入代码,请告诉我!
library(shiny)
library(tidyverse)
India <- read.csv("D:/R/Practice 3/Indiadata.csv")
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Deaths vs all variables "),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("Deaths", "All variables:",
choices = c("cases"="total_cases","vaccinations"="total_vaccinations",
"people vaccinated"="people_vaccinated","people fully vaccinated"="people_fully_vaccinated",
"total booster"="total_boosters","new vaccinations"="new_vaccinations", "median age"="median_age"))
)
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel(plotOutput("plot1")),
tabPanel(plotOutput("plot2")),
tabPanel(plotOutput("plot3")),
tabPanel(plotOutput("plot4")),
tabPanel(plotOutput("plot5")),
tabPanel(plotOutput("plot6")),
tabPanel(plotOutput("plot7"))
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$plot1 <- renderPlot({
ggplot(India,aes(y=total_deaths,x=total_cases))
})
output$plot2 <- renderPlot({
ggplot(India,aes(y=total_deaths,x=total_vaccinations))
})
output$plot3 <- renderPlot({
ggplot(India,aes(y=total_deaths,x=people_vaccinated))
})
output$plot4 <- renderPlot({
ggplot(India,aes(y=total_deaths,x=people_fully_vaccinated))
})
output$plot5 <- renderPlot({
ggplot(India,aes(y=total_deaths,x=total_boosters))
})
output$plot6 <- renderPlot({
ggplot(India,aes(y=total_deaths,x=new_vaccinations))
})
output$plot7 <- renderPlot({
ggplot(India,aes(y=total_deaths,x=median_age))
})
}
# Run the application
shinyApp(ui = ui, server = server)
解决方案
mainPanel
是sidebarLayout()
函数的参数。所以,你只需要把它移到sidebarLayout()
函数中:
ui <- fluidPage(
# Application title
titlePanel("Deaths vs all variables "),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("Deaths", "All variables:",
choices = c("cases"="total_cases","vaccinations"="total_vaccinations",
"people vaccinated"="people_vaccinated","people fully vaccinated"="people_fully_vaccinated",
"total booster"="total_boosters","new vaccinations"="new_vaccinations", "median age"="median_age"))
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel(plotOutput("plot1")),
tabPanel(plotOutput("plot2")),
tabPanel(plotOutput("plot3")),
tabPanel(plotOutput("plot4")),
tabPanel(plotOutput("plot5")),
tabPanel(plotOutput("plot6")),
tabPanel(plotOutput("plot7"))
)
)
)
)
推荐阅读
- python - QAbstractTabelModel.data() 总是得到 index.row() == 0 并且只显示 1 行
- javascript - javascript 中的脚本等于 php 中的 $_SERVER['SCRIPT_FILENAME'] 是什么?
- gremlin - 在 gremlin 上过滤顶点
- spring - 使用与 JDL 的多对多关系时出错 - JHipster
- tensorflow - 如何在 Raspi 3 上使用 libtensorflow-lite.a?
- rest - golang gorilla/mux 和 rest GET 问题
- c++ - 如何从 C++ 代码中禁用 Windows DPI 虚拟化?
- python-3.x - 在 torchvision 模型中查找所有 ReLU 层
- c - 读取搜索算法完成的比较次数
- python - 读取数据框的困难