大佬教程收集整理的这篇文章主要介绍了Shiny App 中反应条形图的问题,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试生成一个闪亮的应用程序,它可以被动地创建此条形图。它是一个条形图,纵轴表示接种疫苗的人数,横轴表示纽约或波士顿等地区。
我包含了完整的代码,我不知道为什么如果我放入 hchart: y = df [,2] 它可以工作,但是如果我放入 y = df [,colm] 它没有。有什么建议吗?
# librarIEs
librarIEs <- c("Jsonlite","ggplot2")
for(lib in librarIEs){
eval(bquote(library(.(lib))))
}
if (!require("pacman")) install.packages("pacman")
pacman::p_load(shiny,ggplot2,plotly,shinythemes,shinyWidgets,highcharter,DT)
df = data.frame(
zone = c("Boston","NY","Chicago"),teenagers = c(533,489,584),adults = c(120,201,186),elder = c(156,153,246)
)
ui2 <- navbarPage(
paste('Vaccination Evolution in USA'),theme = shinytheme("cerulean"),tabPanel('Evolution by age',sIDebarLayout(
sIDebarPanel(
SELEcTinput('variable',h5('SELEct the age range to visualize'),choices = c("Teens" = 2,"Adults" = 3,"Elder" = 4),SELEcted=2
),HelpText("Age range in USA")
),mainPanel(
textoutput("text1"),titlePanel(h4('Evolution of the vaccination in USA by age and zone')),highchartOutput('histogram'),br(),HelpText("Interact with the graph")
)
)
)
)
# Server building
server2 <- function(input,output) {
output$text1 <- renderText({
colm = as.numeric(input$variablE)
paste("Age group shown is:",names(df[colm]))
})
output$histogram <- renderHighchart({
colm = as.numeric(input$variablE)
hchart(df,type = 'column',hcaes(x = df[,1],y = df[,colm]),name = "number of people vaccinated")%>%
hc_title(text = paste("number of people vaccinated with at least one dose" ),style = List(FontWeight = "bold",FontSize = "20px"),align = "center")%>%
hc_yAxis(title=List(text=paste("number")))%>%
hc_xAxis(title=List(text=paste('Region')))%>%
hc_add_theme(hc_theme_ggplot2())
})
}
#shiny APP
shinyApp(ui = ui2,server = server2)
您应该将变量名称传递给 hcaes
。 y 变量是 names(df[colm]))
,可以使用 !!sym()
将其转换为符号表达式:
output$histogram <- renderHighchart({
colm = as.numeric(input$variablE)
hchart(df,type = 'column',hcaes(x = zone,y = !!sym(names(df[colm]))),name = "number of people vaccinated")%>%
hc_title(text = paste("number of people vaccinated with at least one dose" ),style = list(fontWeight = "bold",fontSize = "20px"),align = "center")%>%
hc_yAxis(title=list(text=paste("number")))%>%
hc_xAxis(title=list(text=paste('Region')))%>%
hc_add_theme(hc_theme_ggplot2())
})
以上是大佬教程为你收集整理的Shiny App 中反应条形图的问题全部内容,希望文章能够帮你解决Shiny App 中反应条形图的问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。