![](/img/trans.png)
[英]How to get the vector character inputs from checkboxGroupinput and convert in to a numeric score
[英]How can I pass a vector of character string labels, taken from an input data frame, as options in a checkboxGroupInput
因此,我嘗試獲取輸入文件,讀取列名,然后將其作為checkboxGroupInput()
的選項返回。
當前,它提取列名並將其作為字符串向量返回,但我無法使用該向量作為checkboxGroupInput
中的checkboxGroupInput
。
注意:服務器的實際代碼使用read.csv(file = file1$datapath)
和上載的文件(並且正常工作),但是我不知道如何在此復制中包括.csv文件。 因此,為了創建可重現的示例,我嘗試在此處使用read.table()
和數據框的文本表示形式(可能無法完美運行)。
library(shiny)
df <- "substrate rep treatment time RFU
1 1 1 live 9:56 137,813.04
2 1 2 live 9:57 135,673.5
3 1 3 live 9:57 138,597.51
4 1 kill killed 9:57 138,111.29
5 2 1 live 9:58 131,257.6
6 2 2 live 9:58 129,746.85"
ui <- fluidPage(
titlePanel("File Upload"),
sidebarLayout(
sidebarPanel(
fileInput(inputId = "data", label = "Data")
),
mainPanel(
uiOutput("names")
),
checkboxGroupInput("design.variables", "Design Variables",
uiOutput("names")
)
)
)
server <- function(input, output){
nms <- reactive({
file1 <- input$data
if(is.null(file1)){return()}
d_uncal <- read.table(file = df
header = TRUE, stringsAsFactors = FALSE)
nm <- names(d_uncal)
nm
})
output$names <- renderPrint({
if(is.null(nms()))
return()
else
nms()
})
}
shinyApp(ui = ui, server = server)
我無法運行您的示例,似乎有一些錯誤。 但是,這是您可以嘗試解決問題的簡要說明。
讀取文件后,可以使用updateCheckboxGroupInput
更改輸入選項的值。 假設您的nms()
反應性對象正常工作,則可以在其后添加以下代碼塊:
observeEvent(nms(), {
updateCheckboxGroupInput(session, "design.variables", choices = nms())
})
那么這將更新的價值choices
上的checkboxGroupInput
每當nms()
的變化。 你需要做的另外一個變化,就是要通過session
通過指定服務器的功能對象到您的服務器:
server <- function(input, output, session) { ... # Everyhing else }
看看我的答案,關於更新的輸入值,類似的問題在這里使用的另一個例子update*
功能。
PS。 uiOutput
用於從renderUI
給定的輸出中創建ui元素。 renderPrint
創建一個字符串,其中包含您通常會在控制台上看到的打印輸出-要在ui中顯示文本,必須使用textOutput
函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.