如何解决为了在功能中使用它,如何提取用户在闪亮的应用程序中选择的滑块的值?
所以我有一个带有滑块的可复制的闪亮应用程序:
library(bold)
library(shiny)
library(shinyWidgets)
library(stringr)
library(readr)
grades2<-function(groups){
taxon<-bold_seqspec(taxon=groups,format = "tsv")
taxon2<-taxon[taxon$species_name!=""|is.na(taxon$species_name),]
taxon2<-taxon2[!(taxon2$bin_uri == "" | is.na(taxon2$bin_uri)),]
taxon2$base_number=str_count(taxon2$nucleotides,pattern="[A-Z]")
taxon2<-taxon2[(taxon2$base_number>input$seqsize),]
assign('taxon',taxon,envir=.GlobalEnv)
}
ui <- navbarPage(title=tags$h3("APP"),tabPanel(column(12,align="center",tags$h4("Download"),tags$br(),sliderInput("seqsize","Mininum number of base pairs for sequences in reference library:",min = 0,max = 1000,value = 500),textOutput("SliderText"),textInputAddon(inputId="taxa2",addon=icon("search"),width="500px",label=tags$h5(tags$strong("Enter the name of the taxonomic group or groups separated by commas,without spaces:")),placeholder="Example: Carnivora,Ursidae,Artiodactyla,Soricomorpha"),downloadButton("downloadData_2","Download"))))
server <- function(input,output){
taxaInput_2 <- reactive({grades2(unlist(strsplit(input$taxa2,",")))})
output$downloadData_2 <- downloadHandler(
filename = function() {
paste(to_upper_camel_case(input$taxa2,sep_out=","),".tsv")
},content = function(file) {
shiny::withProgress(
value=10,{
shiny::incProgress(10/10)
write_tsv(taxaInput_2(),file)
}
)
}
)
}
shinyApp(ui=ui,server=server)
我创建了一个滑动条输入,但是我不知道如何提取用户选择的值,因此无法在名为“ grades2”的函数中使用它。我想要的是在此代码行中将变量“ input $ seqsize”设置为用户在滑块中选择的值:
taxon2<-taxon2[(taxon2$base_number>seqsize),]
问题是我遇到以下错误:
Warning: Error in [.data.frame: object 'input' not found
在此先感谢您的回答
解决方法
我建议您重写函数以删除任何反应性概念:使其天真地知道它在shiny
内运行。
grades2<-function(groups,size){
taxon<-bold_seqspec(taxon=groups,format = "tsv")
taxon2<-taxon[taxon$species_name!=""|is.na(taxon$species_name),]
taxon2<-taxon2[!(taxon2$bin_uri == "" | is.na(taxon2$bin_uri)),]
taxon2$base_number=str_count(taxon2$nucleotides,pattern="[A-Z]")
taxon2<-taxon2[(taxon2$base_number>size),]
assign('taxon',taxon,envir=.GlobalEnv)
}
和
taxaInput_2 <- reactive({grades2(unlist(strsplit(input$taxa2,",")),input$seqsize)})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。