避免过多的滑块输入

时间:2018-06-14 01:13:40

标签: r shiny slider

我有点新鲜,但有R经验。

简而言之,我有一个目前实现了20个滑块输入的shinyApp,但这使得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)

0 个答案:

没有答案