r-闪亮时无输出

  • 本文关键字:输出 r shiny
  • 更新时间 :
  • 英文 :


我尝试在信息部分打印文本,为封面19的病例和死亡分别绘制图表,并在摘要部分为每个月制作汇总表。但现在,只有侧边栏显示,文本和图形根本不显示。我想服务器有错误。R但是,我检查了好几次代码,仍然不知道问题出在哪里。有人能帮忙吗?

ui。R

library(shiny)
library(ggplot2)
library(dplyr)
data<-read.csv('https://raw.githubusercontent.com/lingling1123/covid-19-data/master/us.csv')
data$date<-as.numeric(as.Date(data$date,origin='2020-01-21'))-18281
data$cases<-data$cases/1000
data$deaths<-data$deaths/1000
Jan<-c(1:11)
Feb<-c(12:40)
Mar<-c(41:71)
Apr<-c(72:101)
May<-c(102:132)
Jun<-c(133:162)
Jul<-c(163:193)
Aug<-c(194:224)
Sep<-c(225:254)
Oct<-c(255:285)
Nov<-c(286:298)

# Define UI for application that draws a histogram
shinyUI(navbarPage('All you can know',
# Information
tabPanel('Information',
mainPanel(
textOutput("info"),
)
),
# Summaries
tabPanel('Summaries',
sidebarLayout(
sidebarPanel(
h4('You can create plots using the radio buttons below.'),
radioButtons('var',h5('Select the variable '),choices=list('cases','deaths')),
h4('You can create numerical summaries below.'),
selectizeInput("mon", h5('Select the month you want to check'),selected = "Jan", choices = c('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct'))
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
tableOutput("table")
)
)
)))

服务器。R

shinyServer(function(input,output,session) {

output$info <- renderPrint({
print('For this project, I use Covid19 dataset that incluses date, cases and deaths to make a exposure notification app.')
})




value<-reactive({
variables<-input$var
})
output$distPlot <- renderPlot({
if(value()=='cases'){
ggplot(data,aes(x=date,y=cases))+geom_point()
}else{
ggplot(data,aes(x=date,y=deaths))+geom_point()
}     
}
)

}
)

将数据加载部分从ui.r移动到server.r,例如

ui.r

library(shiny)
library(ggplot2)
library(dplyr)
# Define UI for application that draws a histogram
shinyUI(navbarPage('All you can know',
# Information
tabPanel('Information',
mainPanel(
textOutput("info"),
)
),
# Summaries
tabPanel('Summaries',
sidebarLayout(
sidebarPanel(
h4('You can create plots using the radio buttons below.'),
radioButtons('var',h5('Select the variable '),choices=list('cases','deaths')),
h4('You can create numerical summaries below.'),
selectizeInput("mon", h5('Select the month you want to check'),selected = "Jan", choices = c('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct'))
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
tableOutput("table")
)
)
)))

server.r

data<-read.csv('https://raw.githubusercontent.com/lingling1123/covid-19-data/master/us.csv')
data$date<-as.numeric(as.Date(data$date,origin='2020-01-21'))-18281
data$cases<-data$cases/1000
data$deaths<-data$deaths/1000
Jan<-c(1:11)
Feb<-c(12:40)
Mar<-c(41:71)
Apr<-c(72:101)
May<-c(102:132)
Jun<-c(133:162)
Jul<-c(163:193)
Aug<-c(194:224)
Sep<-c(225:254)
Oct<-c(255:285)
Nov<-c(286:298)
shinyServer(function(input,output,session) {

output$info <- renderPrint({
print('For this project, I use Covid19 dataset that incluses date, cases and deaths to make a exposure notification app.')
})

value<-reactive({
variables<-input$var
})
output$distPlot <- renderPlot({
if(value()=='cases'){
ggplot(data,aes(x=date,y=cases))+geom_point()
}else{
ggplot(data,aes(x=date,y=deaths))+geom_point()
}     
}
)

}
)

最新更新