我试图建立一个简单的闪亮的应用程序,但不能得到它的工作。我想选择一个州,然后应用程序应该计算臭氧水平的sample.measurement的该状态的平均值。这是我的ui.R代码:
require(shiny)
fluidPage(pageWithSidebar(
headerPanel("Ozone Pollution"),
sidebarPanel(
h3('State'),selectInput("inputstate","Select State",state.name)),
mainPanel(
h3('Results'),verbatimTextOutput("res")
)
))下面是我的server.R程序:
require(dplyr)
library(shiny)
shinyServer(
function(input, output) {
stat_state<-reactive({filter(ozone_2015,State.Name==input$inputstate)})
output$res<- renderPrint({mean(stat_state$Sample.Measurement)})
}
)有什么提示吗?谢谢……
发布于 2016-08-24 00:44:17
虽然我不能复制你的数据集,因为我不知道ozone_2015是从哪里来的,但我认为你的问题是你没有像这样引用“反应式”对象:
stat_state()
一旦创建了一个反应对象,除了反应值和输入$ variables之外,你需要在变量的末尾加上'()‘来引用它。
下面是一个将您的一些代码与其他数据集一起使用的示例。希望这能有所帮助。
require(shiny)
ui <-
fluidPage(pageWithSidebar(
headerPanel("Population"),
sidebarPanel(
h3('State'),selectInput("inputstate","Select State",state.name)),
mainPanel(
h3('Results'),verbatimTextOutput("res")
)
))
server <- function(input,output){
require(dplyr)
sample.data <- reactive({as.data.frame(state.x77)})
stat_state <- reactive({sample.data()[which(row.names(sample.data()) == input$inputstate),]})
output$res <- renderPrint({stat_state()$Population})
}
)
}
shinyApp(ui = ui, server = server)https://stackoverflow.com/questions/39106404
复制相似问题