r - 避免过多的滑块输入
问题描述
我对闪亮有点陌生,但在 R 方面有经验。
简而言之,我有一个闪亮的应用程序,它目前实现了 20 个滑块输入,但这让 UI 看起来又脏又乱。我已经探索过用 div() 包装输入语句来调整高度,但后来我松开了滑块的标签。我也尝试过其他输入,但我正在寻找更有说服力的东西。
我记得有人很了解闪亮的讨论覆盖地图的少量输入,但我没有运气在网上找到任何东西。有人能指出我合适的资源吗?
下面是我的代码。我知道在某些情况下我可以使用一些响应式函数并进行一些一般性的整理,但我稍后会进行这些调整。
ui <- fluidPage(
titlePanel(h2('Weather Application', align = 'center' )),
sidebarLayout(
sidebarPanel(
selectInput(inputId = 'fiscalmonth',
label = 'Select a month',
choices = c(1:12),
selected = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'ames',
label = 'AMES',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'atlanta',
label = 'ATLANTA',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'bangor',
label = 'BANGOR',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'bozeman',
label = 'BOZEMAN',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'columbus',
label = 'COLUMBUS',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'dallas',
label = 'DALLAS',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'denver',
label = 'DENVER',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'houston',
label = 'HOUSTON',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'lansing',
label = 'LANSING',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'losangeles',
label = 'LOS ANGELES',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'madison',
label = 'MADISON',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'memphis',
label = 'MEMPHIS',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'miami',
label = 'MIAMI',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'minneapolis',
label = 'MINNEAPOLIS',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'peoria',
label = 'PEORIA',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'pittsburgh',
label = 'PITTSBURGH',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'richmond',
label = 'RICHMOND',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'sacramento',
label = 'SACRAMENTO',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'seattle',
label = 'SEATTLE',
min = 0,
max = 100,
value = 100,
step = 1),
#adding widgit for user to set individual city weight
sliderInput(inputId = 'syracuse',
label = 'SYRACUSE',
min = 0,
max = 100,
value = 100,
step = 1)
),
mainPanel(
plotOutput('map', height = 800),
plotOutput('scatter', height = 800)
)
)
)
server <- function(input, output){
output$map <- renderPlot({
country <- map_data('usa')
country %>% ggplot(aes(long, lat)) +
geom_path(aes(group = group)) +
geom_point(aes(Long, Lat),
size = input$ames/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Ames')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Ames')) +
geom_point(aes(Long, Lat),
size = input$atlanta/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Atlanta')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Atlanta')) +
geom_point(aes(Long, Lat),
size = input$bangor/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Bangor')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Bangor')) +
geom_point(aes(Long, Lat),
size = input$bozeman/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Bozeman')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Bozeman')) +
geom_point(aes(Long, Lat),
size = input$columbus/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Columbus')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Columbus')) +
geom_point(aes(Long, Lat),
size = input$dallas/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Dallas')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Dallas')) +
geom_point(aes(Long, Lat),
size = input$denver/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Denver')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Denver')) +
geom_point(aes(Long, Lat),
size = input$houston/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Houston')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Houston')) +
geom_point(aes(Long, Lat),
size = input$lansing/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Lansing')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Lansing')) +
geom_point(aes(Long, Lat),
size = input$losangeles/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Los Angeles')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Los Angeles')) +
geom_point(aes(Long, Lat),
size = input$madison/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Madison')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Madison')) +
geom_point(aes(Long, Lat),
size = input$memphis/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Memphis')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Memphis')) +
geom_point(aes(Long, Lat),
size = input$miami/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Miami')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Miami')) +
geom_point(aes(Long, Lat),
size = input$minneapolis/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Minneapolis')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Minneapolis')) +
geom_point(aes(Long, Lat),
size = input$peoria/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Peoria')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Peoria')) +
geom_point(aes(Long, Lat),
size = input$pittsburgh/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Pittsburgh')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Pittsburgh')) +
geom_point(aes(Long, Lat),
size = input$richmond/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Richmond')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Richmond'), hjust = 1.5) +
geom_point(aes(Long, Lat),
size = input$sacramento/7, colour = 'green', alpha = .15,
data = ctycord %>% filter(City == 'Sacramento')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Sacramento'), hjust = -0.5) +
geom_point(aes(Long, Lat),
size = input$seattle/7, colour = 'green', alpha = .19,
data = ctycord %>% filter(City == 'Seattle')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Seattle'), hjust = -0.6) +
geom_point(aes(Long, Lat),
size = input$syracuse/7, colour = 'green', alpha = .19,
data = ctycord %>% filter(City == 'Syracuse')) +
geom_text(aes(Long, Lat, label = City), data = ctycord %>% filter(City == 'Syracuse'), hjust = -0.5) +
theme_void()
})
}
shinyApp(ui=ui, server=server)
解决方案
推荐阅读
- mysql - 为什么mysql存储函数不断删除所有行?
- swift - 我试图在用户键入时从 firebase 读取数据,但出现此错误:线程 1: EXC_BAD_ACCESS (code=2, address=0x7ffeed614ff8)
- pyspark - 如何根据同一列的条件更改 PySpark 数据框中的值?
- hibernate - WebLogic 12C 应用服务器版本-12.2.1.2.0 类加载器问题
- time - 算法的时间复杂度(伪代码)
- dart - 如何将 StreamBuilder 与 Observable 一起使用?
- npm - Npm 缺少脚本:start-win
- maven - 火花:类未找到异常
- html - 在 HTML 表格中显示特定的行数
- ruby-on-rails - 在 Rails 5 中解析 url 时如何将“/api”附加到“localhost:3000”?