现在,我正在制作一个闪亮的应用程序,该应用程序根据不同的时间显示一些数据,以显示天气预报的直方图。用户必须从滑块中选择小时,并根据直方图的变化进行选择,但是现在我必须一直写小时输入,并且我想使其成为一个函数,这样我就不必一直写
# Define UI for application that draws a histogram
ui <- fluidPage(theme = shinytheme("superhero"),
# Application title
titlePanel("DLR-VALUES(normal_error) FOR DIFFERENT STATIONS"),
sidebarLayout(
sidebarPanel(
#implementing radio buttons
radioButtons("p", "Select station-id",
list("ALNMRGA1"='a', "COOKOLV1"='b', "COOKOLV3"='c',"DRSS1ST1"='c',"GSHTEM1"='d',"GSWSILM"='e',"GSCFTY1"='f',"GSD5531"='g',"GSHASET"='h',"GSHTEM2"='i',"GSNPRM1"='j',"GSOAKSK1"='k',"ROSSLEX1"='l',"OR_Ln60_1"='n',"COOKOLV2"='o')),
textInput("name", "HOURS", ""),
#slider input for bins of histogram
sliderInput("HOURS",
"RATING BY HOURS:",
min = 1,
max = 48,
value = 1)),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define the server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
if(input$p=='a'&& input$HOURS==1){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='1'])
}
if(input$p=='a'&& input$HOURS==2){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='2'])
}
if(input$p=='a'&& input$HOURS==3){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='3'])
}
if(input$p=='a'&& input$HOURS==4){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='4'])
}
if(input$p=='a'&& input$HOURS==5){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='5'])
}
if(input$p=='a'&& input$HOURS==6){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='6'])
}
if(input$p=='a'&& input$HOURS==7){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='7'])
}
if(input$p=='a'&& input$HOURS==8){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='8'])
}
if(input$p=='a'&& input$HOURS==9){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='9'])
}
if(input$p=='a'&& input$HOURS==10){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='10'])
}
if(input$p=='a'&& input$HOURS==11){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='11'])
}
if(input$p=='a'&& input$HOURS==12){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='12'])
}
if(input$p=='a'&& input$HOURS==13){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='13'])
}
if(input$p=='a'&& input$HOURS==14){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='14'])
}
if(input$p=='a'&& input$HOURS==15){
normalized_dlr_error<-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours=='15'])
}
# draw the histogram with the specified number of bins
hist(normalized_dlr_error, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
怎么样
if(input$p=='a'){
normalized_dlr_error <-print(ty_normal_new_whole_data$normal_error[ty_normal_new_whole_data$Prediction_by_hours==input$HOURS])
}
这将使用输入的值进行过滤。