如何解决根据文本框中的输入将一些响应评分为 1 或 0
以下是我的应用程序,这是一个解释我想要什么的视频。这是我的第一个应用程序,所以我很困惑我应该如何制作它。我想将我的数据编码为 1 或 0。数据将是 MCQ 问题的答案,例如 ABCD,我想将正确答案评分为 1,错误答案评分为 0。
用户界面:
library(shiny)
library(DT)
shinyUI(
navbarPage(title="Analysis",tabPanel(title="Input",sidebarLayout(
sidebarPanel(
fileInput("file","Upload the file"),checkboxInput('file_has_headers',"Take Column Names from the first row of the file",value= TRUE),checkboxInput('show_head_only',"Display only first 6 rows. Uncheck this to see entire file",radioButtons(inputId = 'sep',label = 'Separator',choices = c(Comma=',',Semicolon=';',Tab='\t',Space=''),selected = ','),textAreaInput("domains",'Enter the comma seperated list of dimensions,for example: verbal ability,numerical ability' ),width = 4
),mainPanel(
wellPanel(
DT::dataTableOutput("uploaded_table"
),# Displays the uploaded table by using js dataTable from DT package
),width = 8
),position = 'left'
)
),#End of Input Tab panel
tabPanel(title="Verification",fillCol(uiOutput('choose_columns')),## end of fillRow
),#End of Verification Tab Panel
navbarMenu(title="Analayis",tabPanel(title="Item Analysis","content"
),#End of Item Analysis Tab Panel
tabPanel(title="Test Analysis","content"
) #End of Test Analysis Tab Panel
) #End of navbarMenu
) #End of navbarPage
) #end of shinyUI
服务器:
library(shiny)
library(DT)
options(shiny.maxRequestSize=300*1024^2)
shinyServer(function(input,output) {
#1: Get the uploaded file in the data variable
data <- reactive({
uploaded <- input$file
#if(is.null(file1)){return("No file is selected or selected file is not in the right format. Please check the documentation and upload correct file.")}
req(uploaded) #req retruns a silence rather than error and is better than using if()
if(input$show_head_only){
head(read.csv(file=uploaded$datapath,sep=input$sep,header = input$file_has_headers)) #head() returns only first 6 rows
} else {
read.csv(file=uploaded$datapath,header = input$file_has_headers)
}
})
#3: set element to show the uploaded csv file as a table
output$uploaded_table<- DT::renderDataTable(
data(),# If a variable contains the output of reactive() function,it must be used as a function.
server=TRUE,#Important to keep this as true so that large datasets do not crash the browser
options = list(
scrollX = TRUE
),) # End of uploaded table output setting
#4: Set dynamic checkboxes based on the number of columns in the data
output$choose_columns <- renderUI({
n <- length(names(data()))
colnames <- names(data())
items <- strsplit(input$domains,')[[1]]
tagList(
lapply(1:n,function(i){
div(
div(style="display: inline-block; vertical-align:top; width: 150px ;",checkboxInput(paste0('Columns',i),"",value = TRUE )),div(style="display: inline-block; vertical-align:top; width: 150px ;",textInput(paste0('answer_key',placeholder = 'e.g. A')),selectInput(inputId = "domains",label = "",choices = items)),textInput(paste0('valid_options',placeholder = 'e.g. A,B,C,D'))
)
})
)
})
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。