【问题标题】:How to take arguments, accept user input and store data?如何接受参数、接受用户输入和存储数据?
【发布时间】:2020-06-30 17:18:11
【问题描述】:

我有一份清单

PID_short  PID_full 
   420     44101445
   419     44101375
   418     44101344
   417     44100125
   416     44095813
   415     44100240
data <- data.frame(PID_short = seq(from = 420, to = 415, by = -1),  
                   PID_full = c(44101445, 44101375, 44101344, 44100125, 44095813, 44100240))

我想创建一个图形用户界面,当我输入PID_short 时,它会显示PID_full。 例如,当我输入420 时,它会显示44101445。

我对@9​​87654327@ 真的很陌生。但我试过了,这是我的代码:

  library(shiny)

ui <- shinyUI(fluidPage(

  titlePanel(title=h3("Please select the information :", align = "center")),
  sidebarLayout(
    sidebarPanel(
      sliderInput("slide","Select the value of PID_short ", min = 415, max = 420, value = 417)      
      ),
    mainPanel(
      textOutput("out")
    ))))


server <- shinyServer(function(input,output){

  output$out <- renderText(
    paste("The PID_full is:",input$slide)
)})

shinyApp(ui = ui, server = server)

我应该在哪里修改我的代码?或者我应该如何以更好的方式写作?请帮助我...我将不胜感激。

【问题讨论】:

    标签: r user-interface shiny


    【解决方案1】:

    您可以过滤数据框,以便仅保留 PID_short 等于输入的行。然后你用select选择PID_full的值:

    library(shiny)
    library(dplyr)
    
    data <- data.frame(PID_short = seq(from = 420, to = 415, by = -1),  
                       PID_full = c(44101445, 44101375, 44101344, 44100125, 44095813, 44100240))
    
    ui <- shinyUI(fluidPage(
    
      titlePanel(title=h3("Please select the information :", align = "center")),
      sidebarLayout(
        sidebarPanel(
          sliderInput("slide","Select the value of PID_short ", min = 415, max = 420, value = 417)      
        ),
        mainPanel(
          textOutput("out")
        ))))
    
    
    server <- shinyServer(function(input,output){
    
      output$out <- renderText(
        paste("The PID_full is:", 
              data %>% 
                filter(PID_short %in% input$slide) %>% 
                select(PID_full))
      )})
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 它有效!非常感谢你。真的真的很多。祝您保持健康并摆脱 COVID-19。我再次非常感谢。我无法在这里表达我的感激之情,但是是的,谢谢!!!
    猜你喜欢
    • 1970-01-01
    • 2015-08-02
    • 2019-01-11
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 2011-09-08
    • 2021-09-11
    • 1970-01-01
    相关资源
    最近更新 更多