r - 如何接受参数、接受用户输入和存储数据?
问题描述
我有一个清单
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
。
我真的很陌生R
。但我试过了,这是我的代码:
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)
我应该在哪里修改我的代码?或者我应该如何以更好的方式写作?请帮助我...我将非常感激。
解决方案
您可以过滤数据框,以便只保留PID_short
等于输入的行。然后选择PID_full
with的值select
:
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)
推荐阅读
- c# - 公共静态 DateTime 字段是一种反模式还是一种好的做法?
- amazon-web-services - 设计带有标签的相册的最佳实践
- python - 在某些元素处打破循环
- python - 抓取具有多个属性的标签
- apache-spark - json/文本格式的 Apache Spark DAG 可视化
- sql - 使用变量 sql 作为列名
- javascript - VueJs 2:将选定的子复选框与父级映射
- google-app-engine - 无法赋值'
' 属性 'XXX' - java - 未处理 Google PubSub 重新发送的消息
- javascript - 如何在Javascript中选择两个字符之间的文本?