在RShiny

时间:2017-12-12 03:13:17

标签: r shiny

首先,这是我正在处理的应用程序的UI的框架代码:

library(ggplot2)
library(shiny)
library(shinythemes)

player.list <- c('Steph', 'LeBron', 'Kyrie')
names(player.list) <- player.list

ui <- shinyUI(
        navbarPage(theme = shinytheme("united"), h1(style="text-align:center", "Interactive NBA Graphing & Charting Application"),

                   # first tab
                   tabPanel(h3("Shot Charts"), sidebarLayout(
                     sidebarPanel(
                       selectInput("name", "Select Player", choices = player.list, selected = 'Steph'),

                       br(), br(), br(), br(),
                       h5("Author"),
                       a(h5("Nicholas Canova"), href="https://twitter.com/SmokeyCanova")
                     ),
                     mainPanel(
                       h4("Shot Chart of Player"),
                       plotOutput('shotchart')
                     )
                   )),

                   # second tab
                   tabPanel(h3("Shot Type Analysis for Two Seasons"), sidebarLayout(
                     sidebarPanel(
                       selectInput("name", "Select Player", choices = player.list, selected = 'Steph'),

                       br(), br(), br(), br(),
                       h5("Author"),
                       a(h5("Nicholas Canova"), href="https://twitter.com/SmokeyCanova"),
                       p("Draw your own plot?"),

                       downloadButton('downloadChart', 'Download (csv File)')
                     ),
                     mainPanel(
                       h4("Fast Fact"),
                       plotOutput('playerchart')
                     )
                   )),

                   # third tab
                   tabPanel(h3("Assist Networks"), sidebarLayout(
                     sidebarPanel(
                       selectInput("name", "Select Player", choices = player.list, selected = 'Steph'),

                       br(), br(), br(), br(),
                       h5("Author"),
                       a(h5("Nicholas Canova"), href="https://twitter.com/SmokeyCanova")
                     ),
                     mainPanel(
                       h4("Shot Chart of Player"),
                       plotOutput('shotchart')
                     )
                   )),

                   # fourth tab
                   tabPanel(h3("Game Recaps"), sidebarLayout(
                     sidebarPanel(
                       selectInput("name", "Select Player", choices = player.list, selected = 'Steph'),

                       br(), br(), br(), br(),
                       h5("Author"),
                       a(h5("Nicholas Canova"), href="https://twitter.com/SmokeyCanova")
                     ),
                     mainPanel(
                       h4("Shot Chart of Player"),
                       plotOutput('shotchart')
                     )
                   ))
))

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

  output$shotchart <- renderPlot({  
    mydf <- data.frame(x = 1:5, y = 1:5)
    ggplot(mydf, aes(x = x, y = y)) + geom_point()
  })

  output$playerchart <- renderPlot({
    mydf <- data.frame(x = 1:5, y = c(5,4,3,2,1))
    ggplot(mydf, aes(x = x, y = y)) + geom_point()
  })
})

shinyApp(ui, server)

全屏显示,导航栏标题和标签名称看起来不错:

enter image description here 当我缩小窗口的宽度时,它看起来很糟糕:

enter image description here 当我进一步缩小窗口时,到主标题本身包装的程度,它看起来更糟糕:

enter image description here

有关如何改善这一点的任何想法?我通常不会将navbarPage用于我的闪亮应用程序,但是对于我正在处理的应用程序,我想要选项卡功能,每个选项卡在选项卡面板中都有自己的一组输入。任何帮助表示赞赏!

编辑:如果可能的话,我想保留标题标签,尽管这些似乎是造成问题的原因......

EDIT2:我想我可以解决这个问题,如果我可以简单地调整文本大小而不必使用标题标记,但不知道如何做到这一点。

EDIT3:我认为,要做edit2,我需要了解更多关于如何使用标签来操纵css以使页面看起来如我所愿。任何帮助也赞赏!

0 个答案:

没有答案