我使用下面的代码在我的R shiny应用程序中创建一个独立的radioactive列表。
req(files_list_creator_1())
numVar <- asInt(length(files_list_creator_1()))
print(numVar)
taglist = list(radioButtons(inputId = "file_num", label ="File number", choices = c("Choices will appear here")))
for (i in 1:numVar){
taglist = append(taglist, list(radioButtons(inputId = paste("x_var_of_file", i, sep ="_") , label = paste("x Variables of file", i, sep = "-"), choices = c("Choices will appear here"))))
taglist = append(taglist, list(radioButtons(inputId = paste("y_var_of_file", i, sep ="_") , label = paste("y Variables of file", i, sep = "-"), choices = c("Choices will appear here"))))
print(taglist)
}
tagList(taglist)
})
这里files_list_creator_1()是一个React式服务器函数,它读取用户上传的Excel文件作为文件框,然后将它们组合成一个列表,并将此列表作为输出返回。
在运行代码时,应用程序加载时没有任何错误,但无线电广播列表不可见。有人能帮忙解决这个问题吗?我正在使用uiOutput(“Variables”)来输出单选按钮
tagList是一个R函数,taglist是我自己的列表,我在其中存储标记。我认为问题在于tagList应该是这样工作的:tagList(tag1,tag2,....),而我试图让它工作:tagList(list(tag1,tag2,...))如何更改此设置?
下面是一个可复制示例的完整代码和相关部分:
library(shiny)
library(readxl)
library(tidyverse)
library(here)
library(ggplot2)
library(plotly)
library(dplyr)
library(checkmate)
library(reshape2)
library(data.table)
ui <- fluidPage(
titlePanel("Test App"),
mainPanel(
tabsetPanel(
tabPanel(
"Data",
fileInput("file_1", "Please choose Excel file", multiple = TRUE, accept = ".xlsx", buttonLabel = "Browse"),
uiOutput("Variables")
),
tabPanel(
"Comparison Panel",
)
)
)
)
server <- function(input, output, session){
files_list_creator_1 <- reactive({
files_list <- list()
for (paths in input$file_1$datapath){
file_to_add <- as.data.frame(read_excel(paths))
print(as.data.frame(read_excel(paths)))
files_list <- append(files_list, list(file_to_add))
}
return(files_list)
})
#--------------------------------------------
output$variables <- renderUI({
req(files_list_creator_1())
numVar <- asInt(length(files_list_creator_1()))
print(numVar)
taglist = list(radioButtons(inputId = "file_num", label ="File number", choices = c("Choices will appear here")))
for (i in 1:numVar){
taglist = append(taglist, list(radioButtons(inputId = paste0("x_var_of_file", i, sep ="_") , label = paste("x Variables of file", i, sep = "-"), choices = c("Choices will appear here"))))
taglist = append(taglist, list(radioButtons(inputId = paste0("y_var_of_file", i, sep ="_") , label = paste("y Variables of file", i, sep = "-"), choices = c("Choices will appear here"))))
}
do.call("tagList", taglist)
})
shinyApp(ui = ui, server = server)
1条答案
按热度按时间f87krz0w1#
Shiny的UI函数接受列表很好(也没有
renderUI
-你真的需要它吗?)。请查看以下 * 可复制 * 的示例:**编辑:**上面的例子的问题是,你正在使用
uiOutput("Variables")
(“V”)沿着output$variables <- renderUI
(“v”)。因此,不呈现输出。代码的固定版本: