2014-12-26 38 views
0

我想制作一个简单的闪亮分数查询系统。也就是说,当有人输入他的学生证时,他可以得到他的分数。我尝试了很多,但无法得到结果。以下是我构建的框架。那么有谁能告诉我我的程序有什么问题吗?闪亮做分数查询系统

ui.R

library(shiny) 
shinyUI(
pageWithSidebar(
headerPanel("Midterm score"), 

sidebarPanel(
    numericInput("studentid","Student ID:",17220131181990), 
    submitButton("Submit") 
), 

mainPanel(
    h3("You score"), 
    h4("You student id:"), 
    verbatimTextOutput("inputValue"), 
    h4("You midterm score:"), 
    verbatimTextOutput("score") 
) 
) 

server.R

library(shiny) 
data <- read.csv("C:/Users/hmw20_000/Desktop/score.csv") 
shinyServer(
function(input,output){ 
output$inputValue <- renderPrint({input$studentid}) 
output$score <- renderPrint({data$score}) 
} 
) 

分数csv文件有两列:一个是studentid,另一种是当score.So输入studentid ,它可以输出相应的分数。

回答

0

我没有你的数据,所以不能看到这是否工作,但这个想法应该工作。

的逻辑是: 1.获得输入ID,传递到server.R 2.在server.R,发现排在你的学生证 3的数据从该行获得的分数 4 。设置输出文本等于得分

ui.R

library(shiny) 
shinyUI(
pageWithSidebar(
headerPanel("Midterm score"), 

sidebarPanel(
    # Input the id, and set up a button to submit the value 
    numericInput("studentid","Student ID:",17220131181990), 
    actionButton("submitButton","Go!") 
), 

mainPanel(
    h3("Your score:"), 
    verbatimTextOutput("outputscore") 
) 
) 

server.R:

library(shiny) 
data <- read.csv("C:/Users/hmw20_000/Desktop/score.csv") 
shinyServer(
function(input,output){ 

observe({ 
# Check if the button is clicked 
if(input$submitButton==0) return(NULL) 
isolate({ 
# Get the ID from the input 
studentID<-input$studentid 
# Get the row in your data which corresponds to the student 
n<-which(data$studentid==studentID) 
# If it doesn't exist,(or more than one exists), throw an error: 
if(length(n)!=1){score<-"Error!"} 
# Get the score from that row 
if(length(n)==1){score<-score<-data$score[n]}  
# Write the score to the output 
output$outputScore<-renderText({score}) 
}) 
}) 

} 
)