首页 > 解决方案 > 无法创建 1 列数据框的 selectInput

问题描述

我正在尝试使用 selectInput 选择数据样本。我想在我的数据框中构建一个特定 sample_ids 的下拉菜单,并使用它从更大的数据框中将该样本 id 子集化以供以后绘制。但是,我无法正确构建此下拉菜单。

在此处下载两个示例文件

在您的工作目录中创建一个名为“SampleDataFolder”的文件夹,并将 .csv 文件上传到该文件夹​​以运行代码。

任何帮助将不胜感激!提前致谢。

library(shiny)

SpadeFiles <- dir("SampleDataFolder", recursive = TRUE, pattern = "*.csv", full.names = TRUE)   #load .csv files from within "SampleDataFolder"

SpadeData <- tibble(filename=SpadeFiles) %>%
    mutate(file_contents = map(filename,  ~ read_csv(.,skip=3,col_names = c("time", "torque"),
    col_types = cols_only(col_double(),col_double(),col_skip(),col_skip()))))   #mutate file contents

FullSpade <- unnest(SpadeData, cols = c(file_contents))     #unnest file contents

FullSpade <- separate(FullSpade, filename,sep = "/",into = c("folder","sample_id"))     #separate path info into multiple columns

UnqSI <- unique(FullSpade[c("sample_id")])  #create a df of the unique sample_ids

UnqSI[sapply(UnqSI, is.character)] <- lapply(UnqSI[sapply(UnqSI, is.character)], as.factor)     #make the UnqSI a df of factors

UnqSI <- as.data.frame(UnqSI)   #make sure the df is a df

ui <- fluidPage(
    selectInput("ds", "Please select a dataset: ", choices = UnqSI),
)

server <- function(input, output, session) {
    
}

shinyApp(ui, server)

编辑:这是我的工作区和运行时的应用程序的图像。

光标在下拉栏中闪烁,但无论我点击哪里,我都无法看到或选择下拉菜单。

标签: rshiny

解决方案


我使用了您提供的相同代码(除了我包含了 tidyverse 库)并得到了这个:在此处输入图像描述

您是否尝试做一些与此不同的事情?


推荐阅读