我需要显示选择输入选项,这些选项是从可能更改的csv文件列表中呈现的。Shiny UI:为csv文件的长列表中的选择输入渲染名称 - 如何显示?
第一步用户通过单选按钮决定他想检查哪个详细视图。在这里,我只需将路径添加到选定的选项即可指向正确的文件夹。 在第二步中,用户应该能够选择“水果”细节视图。因此,我用gsub过滤了一大堆csv文件,这个工作正常,但名称并未显示在选择输入字段中,此外我只是收到一条错误消息。
为了使它更简单,代码:
ui.R
tabItem(tabName = "mainTab",
# control boxes
fluidRow(
box(
title = "Please select a fruit representation",
width = 12,
status = "info",
color = "maroon",
collapsible = FALSE,
radioButtons(
inputId = "fruit_view",
label = "",
choices = c("Top Fruit View",
"Current Fruit Split",
"Top Fruit & Value Class"),
selected = "Top Fruit View",
inline = TRUE)
)
),
fluidRow(
box(
title = "Selected Fruit:",
width = 4,
collapsible = FALSE,
selectInput(
inputId = "fruit_selection",
label = "",
choices = "")
server.R
get_fruitView <- reactive({
switch(input$fruit_view,
"Top Fruit View" = dir(
path = "data/fruits/", full.names = TRUE),
"Current Fruit Split" = dir(
path = "data/splits/", full.names = TRUE),
"Top Fruit & Value Class" = dir
(path = "data/classes/", full.names = TRUE))
})
# loading the modeled data by fruit
visible_fruits <- reactive({
fruit_choiced <- get(input$fruit_view)
fruit_choice <- view_choiced()[c(gsub(view_choiced(),
pattern = "[^_]+_[^_]+_([^_]+)_[^_]+", replacement = "\\1"))]
basename(unique(fruit_choice))
})
observe({
updateSelectInput(session, "",
choices = visible_fruits())
})
正则表达式工作正常,隔离我想的名字显示,但它们在用户输入中不可见。
在此先感谢。
顺便说一句,我得到这个错误信息:
Warning: Error in serverFuncSource: server.R returned an object of unexpected type: environment
Stack trace (innermost first):
1: shiny::runApp
Error in serverFuncSource() :
server.R returned an object of unexpected type: environment
Warning: Error in get: object 'input' not found
Stack trace (innermost first):
58: get
57: <reactive:visible_channels> [C:\Users\m.nierhoff\Desktop\AnalyseR\RAnalysen\channel-forecasting/server.R#60]
46: visible_channels
45: updateSelectInput
44: observerFunc [C:\Users\m.nierhoff\Desktop\AnalyseR\RAnalysen\channel-forecasting/server.R#69]
1: shiny::runApp
我无法验证我的意见,因为我没有什么数据没有做,但它看起来就像你没有在'updateSelectInput'中放入'inputId'变量一样,'shiny'不知道要更新哪个'selectInput'。 –
使用'''get'''输入$''fruit_view'''将不起作用; '''view_choiced()'''在哪里? – amrrs