[英]Barplot display in R.shiny
i have developed a code to display bar data according to reaction buttons how ever i would like to to know exact number if i move the cursor on the bar of display it next to it我已经开发了一个代码来根据反应按钮显示条形数据,如果我将 cursor 移动到旁边的显示条上,我想知道确切的数字
the code编码
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)
and my data look like我的数据看起来像
a b c d
5 133 258 106
4 59 60 28
1 34 64 28
as matrix作为矩阵
In our project we found this feature was already implemented in plotly:在我们的项目中,我们发现这个功能已经在 plotly 中实现:
https://plot.ly/r/shiny-tutorial/ https://plot.ly/r/shiny-tutorial/
I haven't used plotly for a while, but I believe for your app you would change plotOutput
to plotlyOutput
in your UI, and similarly there's renderPlotly
function in the server side.我有一段时间没有使用 plotly,但我相信对于您的应用程序,您会在 UI 中将
plotlyOutput
plotOutput
同样在服务器端有renderPlotly
function。
Plotly is a little different that standard R plots, but it supports much better interactivity out of the box, so I would recommend it if you plan on making interactive plots. Plotly 与标准 R 绘图略有不同,但它支持更好的开箱即用交互性,因此如果您打算制作交互式绘图,我会推荐它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.