【发布时间】:2018-05-03 04:12:07
【问题描述】:
我正在构建一个闪亮的应用程序来映射两个不同的文本输入。我使用字符串距离进行匹配,但它们可能是错误的。因此,我计划开发一个闪亮的应用程序,主题专家可以使用单击和下拉菜单来选择匹配的唯一数据。
如果我有固定的行数,我可以实现如下所示:: 但是,当我不知道数据中的行数时,如何动态设计用户界面以获得所需的输出?
在用户执行了所需的映射之后。我想在单击按钮后执行一些操作。此外,如果用户单击了映射(复选框)。我想将该行排除在最终操作之外。
library(shiny)
set.seed(42)
n_samp = 5 # this comes from the input
indx <- sample(1:20, n_samp)
let_small <- letters[indx]
let_caps <- sample(LETTERS[indx])
# user input
ui <- fluidPage(
selectInput(inputId = "n_samp_choice", label = NULL,
choices = 1:20, width = 500), # number of samples
fluidRow( # first row checkbox
column(width = 2, offset = 0,
checkboxInput("correct1", label = NULL, FALSE)
),
column(width = 2, offset = 0, # text input originial
textInput(inputId = "original1", value = let_small[1], label = NULL )
),
column(width = 5, # options for match
selectInput(inputId = "options1", label = NULL,
choices = let_caps, width = 500)
)
),
fluidRow(
column(width = 2, offset = 0,
checkboxInput("correct1", label = NULL, FALSE)
),
column(width = 2, offset = 0,
textInput(inputId = "original2", value = let_small[2], label = NULL )
),
column(width = 5,
selectInput(inputId = "options2", label = NULL,
choices = let_caps, width = 500)
)
),
fluidRow(
column(width = 2, offset = 0,
checkboxInput("correct1", label = NULL, FALSE)
),
column(width = 2, offset = 0,
textInput(inputId = "original3", value = let_small[3], label = NULL )
),
column(width = 5,
selectInput(inputId = "options3", label = NULL,
choices = let_caps, width = 500)
)
),
fluidRow(
column(width = 2, offset = 0,
checkboxInput("correct1", label = NULL, FALSE)
),
column(width = 2, offset = 0,
textInput(inputId = "original4", value = let_small[4], label = NULL )
),
column(width = 5,
selectInput(inputId = "options4", label = NULL,
choices = let_caps, width = 500)
)
),
fluidRow(
column(width = 2, offset = 0,
checkboxInput("correct1", label = NULL, FALSE)
),
column(width = 2, offset = 0,
textInput(inputId = "original5", value = let_small[5], label = NULL )
),
column(width = 5,
selectInput(inputId = "options5", label = NULL,
choices = let_caps, width = 500)
),
column(width = 2, offset = 0,
uiOutput("actionBut.out")
)
)
)
server <- function(input, output, session) {
output$actionBut.out <- renderUI({
print(input$original1)
session$sendCustomMessage(type="jsCode",
list(code= "$('#text').prop('disabled',true)"))
actionButton("copyButton1","Copy Code")
})
observeEvent(input$copyButton1, {
if(tolower(input$options1) == tolower(input$options1) &
tolower(input$options2) == tolower(input$options2) &
tolower(input$options3) == tolower(input$options3) &
tolower(input$options4) == tolower(input$options4) &
tolower(input$options5) == tolower(input$options5))
{
print("great job")
}else{
unmapp <- which(c(input$correct1, input$correct2,
input$correct3, input$correct4,
input$correct5))
print("The following are unmatched")
print(let_caps[unmapp])
}
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r user-interface dynamic shiny