我想创建一个带有R Shiny的应用程序,在该应用程序中加载数据,显示它,然后可以对另一个小标题/数据框中的数据进行一些操作,并将原始数据显示在选项卡中。另外,我想将小单元格中的数据用作textInput的值。到目前为止,我已经针对UI提出了这一点:
ui <-
dashboardPage(
dashboardHeader(title="NGS library quantification app", titleWidth=500),
dashboardSidebar(
menuItem(text = "Raw Data", tabName = "r_data", icon=icon("clipboard")),
menuItem(text = "User Data", tabName = "u_data", icon=icon("clipboard")),
menuItem(text = "Analysis", tabName = "analysis", icon=icon("cog", lib = "glyphicon")),
menuItem(text = "Summary", tabName = "summary", icon=icon("book")),
collapsed=TRUE),
dashboardBody(
tags$head(
tags$style(HTML(".main-sidebar { font-size: 30px; }")) #change the font size to 30
),
tags$script(
HTML(
"
$(document).ready(function(){
// Bind classes to menu items, easiet to fill in manually
var ids = ['r_data','u_data','analysis', 'summary'];
for(i=0; i<ids.length; i++){
$('a[data-value='+ids[i]+']').addClass('my_subitem_class');
}
// Register click handeler
$('.my_subitem_class').on('click',function(){
// Unactive menuSubItems
$('.my_subitem_class').parent().removeClass('active');
})
})
"
)
),
tabItems(
#Raw data tab
tabItem(tabName = "r_data", fileInput(inputId = "file", label = "Choose file"), tableOutput("info"), tableOutput("raw_data")),
#user data tab
tabItem(tabName = "u_data",
column(textInput("ID1", "Sample ID", value = ""),
textInput("ID2", "", value = ""),
textInput("ID3", "", value = ""),
textInput("ID4", "", value = ""),
textInput("ID5", "", value = ""),
textInput("ID6", "", value = ""),
textInput("ID7", "", value = ""),
textInput("ID8", "", value = ""),
width=1),
column(numericInput("size1", "library size (bp)", value = NULL, step=1),
numericInput("size2", "", value = NULL, step=1),
numericInput("size3", "", value = NULL, step=1),
numericInput("size4", "", value = NULL, step=1),
numericInput("size5", "", value = NULL, step=1),
numericInput("size6", "", value = NULL, step=1),
numericInput("size7", "", value = NULL, step=1),
numericInput("size8", "", value = NULL, step=1),
width = 2),
column(numericInput("dil1", "First dilution", value = 100000, step=10000),
numericInput("dil2", "", value = 100000, step=10000),
numericInput("dil3", "", value = 100000, step=10000),
numericInput("dil4", "", value = 100000, step=10000),
numericInput("dil5", "", value = 100000, step=10000),
numericInput("dil6", "", value = 100000, step=10000),
numericInput("dil7", "", value = 100000, step=10000),
numericInput("dil8", "", value = 100000, step=10000),
width = 2),
column(numericInput("dil9", "Second dilution", value = 250000, step=10000),
numericInput("dil10", "", value = 250000, step=10000),
numericInput("dil11", "", value = 250000, step=10000),
numericInput("dil12", "", value = 250000, step=10000),
numericInput("dil13", "", value = 250000, step=10000),
numericInput("dil14", "", value = 250000, step=10000),
numericInput("dil15", "", value = 250000, step=10000),
numericInput("dil6", "", value = 250000, step=10000),
width = 2),
column(numericInput("dil17", "Third dilution", value = 500000, step=10000),
numericInput("dil18", "", value = 500000, step=10000),
numericInput("dil19", "", value = 500000, step=10000),
numericInput("dil20", "", value = 500000, step=10000),
numericInput("dil21", "", value = 500000, step=10000),
numericInput("dil22", "", value = 500000, step=10000),
numericInput("dil23", "", value = 500000, step=10000),
numericInput("dil24", "", value = 500000, step=10000),
width = 2),
column(textInput("check1", "Sample Detected?", "YES"),
textInput("check2", "", "YES"),
textInput("check3", "", "YES"),
textInput("check4", "", "YES"),
textInput("check5", "", "YES"),
textInput("check6", "", "YES"),
textInput("check7", "", "YES"),
textInput("check8", "", "YES"),
width = 2)
)
然后是服务器:
server <- function(input, output, session){
# Reading data from CFX exported file
data <- reactive({
inFile <- input$file
if(is.null(inFile))
return(NULL)
data <- read_excel(paste(inFile$datapath), sheet=1, skip=18, col_types = c("text", "text", "text",
"text", "numeric", "numeric", "numeric",
"numeric", "numeric"))
})
ID1 <- reactive({data()[12, 2]})
updateTextInput(session, "ID1", value = reactive({ID1()}))
}
这些只是片段,希望对评估此问题有所帮助。问题是,当我然后返回到用户数据并查看样本ID而不是查看样本ID时,我会看到ID1变量的代码是什么?我不知道我在做什么错。我是Shiny的新手,无法真正解决此问题。您可以找到应用here
这是textInput("ID1", "Sample ID", value = "")
中的输出:
structure(function () ,{, .dependents$register(), if (.invalidated || .running) {, ..stacktraceoff..(self$.updateValue()), }, .graphDependsOnId(getCurrentContext()$id, .mostRecentCtxId), if (.error) {, stop(.value), }, if (.visible) , .value, else invisible(.value),}, observable = <environment>)
但是我期望单元格中的值。任何帮助将不胜感激。谢谢大家
答案 0 :(得分:0)
您需要进行一些更改:
updateTextInput
放入观察者中。这是因为您需要从反应式表达式中读取内容,observe
会这样做。ID1()
解析as.character
,然后才能在应用中显示它。将您的server
更改为以下内容:
server <- function(input, output, session){
# Reading data from CFX exported file
data <- reactive({
inFile <- input$file
if(is.null(inFile))
return(NULL)
data <- readxl::read_excel(paste(inFile$datapath), sheet=1, skip=18,
col_types = c("text", "text", "text","text", "numeric",
"numeric", "numeric","numeric", "numeric"))
})
ID1 <- reactive({data()[12, 2]})
observe({
updateTextInput(session, "ID1", value = as.character(ID1()))
})
}