问题描述
我正在使用 Shiny 构建一个简单的仪表板以在我的工作中使用。一切都很好,直到我发现我无法传递所选输入以用作 ggplot geom_col()
交互参数中的参数。
我的目的是根据 checkboxGroup
的选定值更改交互图,其中选定的值将用作 ggplot 中 fill=interaction(....) 的参数。
我在这个阶段遇到了问题:
ggplot(data= opsdata2,aes(x=reorder(GUDANG,KUANTUM/1000),y=KUANTUM/1000,fill=interaction(get(input$cekgr_fill),sep = "*")
))
'get(input$cekgr_fill)' 只传递第一个参数,而我的目的是在 input$cekgr_fill 中使用至少 2 个参数构建交互条形图,例如: 'fill=interaction(JENIS,TH_ADA,sep="*")'。
'get(input$cekgr_fill)' 只传递第一个参数,即:JENIS,而忽略 TH_ADA。
你能帮我吗?谢谢。
这是我的代码:
shinyUI(dashboardPage(
#Nama Dashboard
dashboardHeader(title = "OPERASIONAL"),dashboardSidebar(
checkboxGroupInput("cekgr_gudang",label = h4("Gudang"),choiceNames = list("Karanganyar","Binong","Rancaudik","Tanjungrasa","Ciwangi"),choiceValues = list("Karanganyar","Ciwangi")
),checkboxGroupInput("cekgr_komoditas",label = h4("Komoditas"),choices = c("Beras","Minyak Goreng","Terigu","Gula","Gabah","Ketan")
),checkboxGroupInput("cekgr_tahun","Tahun",choices = c("2018","2019","2020","2021")
),checkboxGroupInput("cekgr_opsional",label = h4("Opsional"),choices = c("Fumigasi","Kondisi kualitas")
),checkboxGroupInput("cekgr_fill",label = h4("Fill Grafik"),choiceNames = c("JENIS","TAHUN"),choiceValues = c("JENIS","TH_ADA")
),actionButton("OK","Sikaaat")
),## BODY
dashboardBody(
fluidRow(
column(
width = 12,box(title = "Grafik Yang Kamu Minta ",solidHeader = T,width = 8,height = 500,collapsible = T,plotOutput("grafik1"),textOutput("PilihanGudang"),textOutput("PilihanKomoditas"),textOutput("PilihanTahun"),textOutput("FillGrafik"))
)
))))
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input,output) {
#### Pilihan-pilihan
observeEvent(input$OK,{
opsdata1 <- read_xlsx("~/Documents/App-Dashboard-Ops/data_Feb_11.xlsx")
View(opsdata1)
output$PilihanGudang <- renderText({
gudangterpilih <- paste(input$cekgr_gudang,collapse = ",")
paste("Gudang : ",gudangterpilih)})
output$PilihanKomoditas <- renderText({
komoditasterpilih <- paste(input$cekgr_komoditas,")
paste("Komoditas : ",komoditasterpilih)})
output$PilihanTahun <- renderText({
tahunterpilih <- paste(input$cekgr_tahun,")
paste("Tahun : ",tahunterpilih)})
output$FillGrafik <- renderText({
fillterpilih <- paste(input$cekgr_fill,")
paste("Fill : ",fillterpilih)})
opsdata2 <- opsdata1 %>%
filter(GUDANG %in% input$cekgr_gudang) %>%
filter(JENIS %in% input$cekgr_komoditas) %>%
filter(TH_ADA %in% input$cekgr_tahun)
View(opsdata2)
output$grafik1 <- renderPlot({
ggplot(data= opsdata2,sep = "*")
)) +
geom_col() + coord_flip() +
scale_y_continuous(labels = unit_format(unit = "Ton")) +
labs(x="",y="",fill="") +
theme_clean() + theme(legend.position = "top")
})
})
})
here is my data :
structure(list(GUDANG = c("Karanganyar","Karanganyar","Ciwangi",UNIT = c(NA,NA,NA),TUMPUKAN = c(NA,JENIS = c("Beras","Beras","Ketan","Beras"),PSO_KOM_HGL = c("PSO","PSO","KOM","HGL","PSO" ),TH_ADA = c(2020,2019,2020,2018,2018),KUALITAS = c("Med_20%","Med_20%","Kom_10%","Med_5%","Kom_15%","Med_15%"),KEMASAN = c(50,50,10,25,5,50),MEREK = c(NA,"WJ","IBU",NEGARA = c("Indonesia","Indonesia","Thailand","Vietnam","Vietnam"),EXP = c(NA,KONDISI = c("Baik","Baik","Baik"),KUANTUM = c(10000,107500,12810,4150,65000,4391000,222850,320000,3193550,2580,37500,30000,2513060,184720,2040,182200,177270,20000,529400,103500,449755)),row.names = c(NA,-21L),class = c("tbl_df","tbl","data.frame"))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)