条形图显示 R.shiny
Barplot display in R.shiny
我已经开发了一个代码来根据反应按钮显示条形数据,如果我将光标移动到它旁边的显示条上,我想知道确切的数字
代码
library("shiny")
data = data.matrix(MY_data[1:4])
ui=fluidPage(
# Give the page a title
titlePanel("Age ranges according to program"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
actionButton(inputId = "MBA", label = "MBA"),
actionButton(inputId = "MSLOD", label = "MSLOD"),
actionButton(inputId = "MSQBE", label = "MSQBE")
),
# Create a spot for the barplot
mainPanel(
plotOutput("hist")
)
)
)
server <- function(input, output) {
rv <- reactiveValues(data = data[1,1:4])
observeEvent(input$MBA, { rv$data <- data[1,1:4] })
observeEvent(input$MSLOD, { rv$data <- data[2,1:4] })
observeEvent(input$MSQBE, { rv$data <- data[3,1:4] })
output$hist <- renderPlot({
barplot(rv$data,
main=input$radio,
ylab="Number employees",
xlab="Ages Range",col=rainbow(4))
})
}
shinyApp(ui = ui, server = server)
我的数据看起来像
a b c d
5 133 258 106
4 59 60 28
1 34 64 28
作为矩阵
在我们的项目中,我们发现此功能已在 plotly 中实现:
https://plot.ly/r/shiny-tutorial/
我已经有一段时间没有使用 plotly 了,但我相信对于您的应用程序,您会在 UI 中将 plotOutput
更改为 plotlyOutput
,同样还有 renderPlotly
服务端的功能。
Plotly 与标准 R 绘图略有不同,但它支持更好的开箱即用交互性,因此如果您打算制作交互式绘图,我会推荐它。
我已经开发了一个代码来根据反应按钮显示条形数据,如果我将光标移动到它旁边的显示条上,我想知道确切的数字
代码
library("shiny")
data = data.matrix(MY_data[1:4])
ui=fluidPage(
# Give the page a title
titlePanel("Age ranges according to program"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
actionButton(inputId = "MBA", label = "MBA"),
actionButton(inputId = "MSLOD", label = "MSLOD"),
actionButton(inputId = "MSQBE", label = "MSQBE")
),
# Create a spot for the barplot
mainPanel(
plotOutput("hist")
)
)
)
server <- function(input, output) {
rv <- reactiveValues(data = data[1,1:4])
observeEvent(input$MBA, { rv$data <- data[1,1:4] })
observeEvent(input$MSLOD, { rv$data <- data[2,1:4] })
observeEvent(input$MSQBE, { rv$data <- data[3,1:4] })
output$hist <- renderPlot({
barplot(rv$data,
main=input$radio,
ylab="Number employees",
xlab="Ages Range",col=rainbow(4))
})
}
shinyApp(ui = ui, server = server)
我的数据看起来像
a b c d
5 133 258 106
4 59 60 28
1 34 64 28
作为矩阵
在我们的项目中,我们发现此功能已在 plotly 中实现:
https://plot.ly/r/shiny-tutorial/
我已经有一段时间没有使用 plotly 了,但我相信对于您的应用程序,您会在 UI 中将 plotOutput
更改为 plotlyOutput
,同样还有 renderPlotly
服务端的功能。
Plotly 与标准 R 绘图略有不同,但它支持更好的开箱即用交互性,因此如果您打算制作交互式绘图,我会推荐它。