2014-12-26 3 views
0

반짝이는 간단한 점수 시스템을 만들고 싶습니다. 누군가가 학생 ID를 입력하면 점수를 얻을 수 있습니다. 나는 많이 시도하지만 결과를 얻을 수는 없다. 아래는 내가 구축 한 프레임 워크입니다. 아무도 내 프로그램에 어떤 문제가 있다고 말할 수 있습니까?Shiny to score query system

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에서 server.R 2로 통과, 학생 ID (3)의 데이터에 행을 찾을 수 4 .

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}) 
}) 
}) 

} 
) 
: 점수

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 동일한 출력 텍스트를 설정합니다