本文介绍了从其他功能的输入面板中进行呼叫选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的闪亮应用程序:

I have a simple shiny app:

读取zip文件.选择一些所需的文件,然后根据读取的文件数调整输入面板:

Read the zip file. Select some desired file and adjust the input panel based on the number of read files:

ui <- fluidPage(
  fileInput("File", "Input checkbox"),
  selectInput("inSelect", "Select input",c())
  leafletOutput("mymap")
)

server <- function(input, output, session) {
  cor<- reactive({
    x=input$File

    if (is.null(x))
      return(NULL)

    report_list <- c("Park result.txt",
                     "Park result minus",
                     "Park result plus")
    temp_files <- unzip(x$datapath)
    temp_files <- temp_files[grepl(paste(report_list, collapse = "|"), temp_files)]

    T=length(temp_files)

    A_new=c();for(i in 1:(T/3)){A_new[[i]]=c()}
    for(i in 1:(T/3)){A_new[[i]]=....}

    result <- list(T=T,A_new=A_new);
    return(result);
  })

observeEvent(cor(),{
updateSelectInput(session, "Select1",
                  label = paste(((cor()$T)/3),"different layout"),
                  choices = paste0("Layout",c(1:((cor()$T)/3))))
})

output$mymap <- renderLeaflet({
    infile=input$File
    if (is.null(infile))
      return(NULL)
    a2=cor()
    leaflet() %>%
      addProviderTiles("OpenTopoMap", group = "MapQuestOpen.Aerial") %>%
      addMarkers(data =a2$A_new[[1]],~long, ~lat, popup = ~as.character(mag), label = ~as.character(Name))%>%

      addMeasure()
  })
}

shinyApp(ui, server)

最后,在我的output$mymap函数中,如何设置参数A_new,如果用户选择layout1,然后绘图显示与A_new[[1]]相关的地图,如果layout2那么地图应该是A_new[[2]]才能显示?!

At the end, in my output$mymap function, how could I set the parameter A_new, in a way that If user choose layout1, then plot show the map related to A_new[[1]] , if layout2 then map should be A_new[[2]] to display ?!

推荐答案

您还可以使用observeEvent,它的代码要少得多

You can also use the observeEvent which is a lot less code

 observeEvent(cor(),{
    updateSelectInput(session, "inSelect",label = paste(cor()$t1,"different layout"),choices = paste0("Layout",c(1:cor()$t1)))
  })

这篇关于从其他功能的输入面板中进行呼叫选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 19:44