您好我尝试通过交互式闪亮应用程序单击运行一组代码。 我对Shiny相对较新,并且在运行单击代码时感到困惑。下面是虚拟代码...
shinyUI(fluidPage(
titlePanel("Pricing Change"),
sidebarLayout(
sidebarPanel(
h3("Select Features"),
selectInput("sku","Select SKU ",
choices = as.character(main_file$Alternatives) ,
selectize = T),
.
.
.
.
actionButton("do", "Click Me")
),
mainPanel(
tableOutput("ckt"),
)))
shinyServer(function(input,output){
sku5 <- reactive({input$sku})
main_file$Alternatives <- as.character(main_file$Alternatives)
#Getting utilities for interpolar price points
interpolar_pp <- reactive({
aa <- spline_plot(main_file,sku5())
return(aa)
})
ck_tab <- data.frame()
output$ckt <- renderTable({ input$do
isolate(
for(z in 1:nrow(interpolar_pp())){
elas_matrix[elas_matrix$bought_sku==sku5(),sku5()] <- interpolar_pp()[z,2]
el_sum <- apply(elas_matrix[,-1],1,sum)
elas_matrix$total_cross_els <- el_sum
#Adding cross price elasticities with feature utilities
Optimizer_panel<-sqldf("select a.*, b.total_cross_els as cross_els
from Optim_panel as a
left join
elas_matrix as b
on a.Alternatives = b.bought_sku")
Optimizer_panel$Total_util <- as.numeric(Optimizer_panel$Feature_Util +
Optimizer_panel$cross_els )
#Ranking skus in each panel based on total utility
Optimizer_panel$Total_util <- Optimizer_panel$Total_util*(-1)
Optimizer_panel <- setDT(Optimizer_panel )
Optimizer_panel[, rank := frank(Total_util),
by = list(RespID)]
#setting counter for selected sku as Top sku
Optimizer_panel <- as.data.frame(Optimizer_panel)
sku1_top <- nrow(Optimizer_panel[Optimizer_panel$Alternatives==sku5() &
Optimizer_panel$rank==1,])
.
ck_tab[z,"Price"] <- interpolar_pp()[z,1]
ck_tab[z,"Count"] <- sku1_top
}
ck_tab })
我面临两个问题
1.I'm subsetting a dataframe by the use of rownumber.
Eg: Multiple skus are selected by user on app
sku <- reactive({input$sku})
#I wanna subset all those rows where my_file$sku is in reactive list created
above
I generally use
rnum <- which(my_file$sku %in% sku)
req_set <- myfile[rnum,] in general R
#Similarly I'm trying to do in shiny server, I created a reactive rnum() and
then trying to subset, on this it throwing an error: argument 1 (type
'list') cannot be handled by 'cat'
2. In my app I'm getting action button but my code is not running (I have
tested my code in general R and its working fine there).
请为我的问题建议补救措施。我在点击代码中灌输反应值时遇到了问题。提前谢谢!