我在一个闪亮的应用程序中有以下代码。我的目标是为";cutFamily2";selectInput小部件基于用户为";机器2";选择输入。
如果我在observerEvent
上使用corte2()
而不是eval(paste0("corte",2))
,应用程序将正常运行。问题是我想要使用CCD_ 4;2〃;在eval(paste0("corte",2))
中将是函数(function(data,n)
(的自变量,因此我可以很容易地生成corte1
、corte2
等
当我使用CCD_ 9运行它时;$:$运算符中的错误对于原子向量"无效;应用程序甚至无法运行。我试图使用enframe()
将其转换为tibble,然后应用程序运行,但我得到了一个";未知或未初始化的列:CutFamily
";错误,SelectInput选项将为空。我也尝试了[[
,但什么都没有。
关于如何解决这个问题有什么想法吗?
library(shiny)
library(shinydashboard)
library(feather)
library(tibble)
library(tidyverse)
Cortes = as_tibble(read_feather("Cortes.feather"))
ui <- dashboardPage(
dashboardHeader(title="Setup"),
dashboardSidebar(
sidebarMenu(
menuItem("Procedimento",tabName = "task_wizard",icon = icon("th"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "task_wizard",
selectInput(paste0("machine",2),"Selecione o tipo de máquina: ",choices = unique(Cortes$Machine)),
selectInput(paste0("cutFamily",2),"Selecione a área de trabalho: ",choices = NULL)
)
)
)
)
server <- function(input, output) {
assign(paste0("corte",2),reactive({
filter(Cortes,Machine == input[[eval(paste0("machine",2))]])
}))
observeEvent(eval(paste0("corte",2)),{
choices <- unique(eval(paste0("corte",2))$CutFamily)
updateSelectInput(inputId = paste0("cutFamily",2),choices = choices)
})
}
shinyApp(ui = ui, server = server)
这是Cortes可移植的
> Cortes
# A tibble: 4 x 3
Machine CutFamily CutFeature
<chr> <chr> <chr>
1 Torno Torneamento Externo Faceamento
2 Torno Torneamento Externo Torneamento
3 Torno Torneamento Externo Chanframento
4 Torno Torneamento Externo Canal radial
tks
你可以试试这个代码-
library(shiny)
ui <- dashboardPage(
dashboardHeader(title="Setup"),
dashboardSidebar(
sidebarMenu(
menuItem("Procedimento",tabName = "task_wizard",icon = icon("th"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "task_wizard",
selectInput(paste0("machine",2),"Selecione o tipo de máquina: ",choices = unique(Cortes$Machine)),
selectInput(paste0("cutFamily",2),"Selecione a área de trabalho: ",choices = NULL)
)
)
)
)
server <- function(input, output) {
observe({
choices <- unique(filter(Cortes,Machine == input[[paste0("machine",2)]])$CutFamily)
updateSelectInput(inputId = paste0("cutFamily",2),choices = choices)
})
}
shinyApp(ui = ui, server = server)