闪亮的

时间:2017-11-29 16:26:34

标签: r shiny

我有几个项目之间的相关值的数据框,我想为我的案例制作一个闪亮的应用程序,给它第一个项目和第二个项目,并返回它们之间的相关性的值,并代表这个结果颜色,即如果相关值大于50,则该数字的颜色为绿色,如果该值小于50,则该数字为红色。 这是我DF的样本

 DF<- structure(list(row = structure(1:100, .Label = c(" Fagr Mango", 
" Green Beans", "10075 - Bashmala", "Adalia Lemon", "African Crimson Grape", 
"African Pear", "Amar Eldain 400G", "Amar Eldain 400G Old", "American Plum", 
"Apricot", "Artichoke old", "Arugula", "Arugula old", "Arugula Rokla Old", 
"Autumn Royal Grape", "Avocado", "Baladi Cabbage", "Baladi Garlic", 
"Banati Grape", "Barbary Figs", "Barhi Dates", "Barshomi Figs", 
"Beet", "Black Eggplant", "Broccoli", "Cantaloupe", "Capsicum", 
"Carrot", "Cauliflower", "Chard", "Chard Old", "Cherry Tomatoes", 
"Chili Pepper", "Chinese Garlic", "Classic Eggplant", "coconut", 
"Cooking Potato", "Coriander", "Coriander old", "Crimson Grape", 
"Cucumber", "Deluxe Dried Dates", "Dessert Peach", "Dill", "Dill old", 
"Doum", "Dried Apricot", "Dried Dates", "Dried Figs 400G", "Dried Figs 400G Old", 
"Dried Plum", "Flame Grape", "Florida Peach", "Fons Mango", "Fruit Lovers", 
"Fruit Lovers Old", "frying Potato", "Gala Apple", "Ginger", 
"Ginger Old", "Golden Apple", "Golden Onion", "Golden Raisin", 
"Granny Apple", "Grape Leaves", "Greek Red Apple", "Greek sugar apple", 
"Green Latoga Lettuce  Old", "Green pepper", "Guava", "Hendi Mango", 
"Hibiscus", "Hollywood Plum", "Hot Pepper", "Iceberg Lettuce", 
"Iceberg Lettuce old", "Imported Apricot", "Imported Banana", 
"Imported Celery old", "Imported Cherry", "Imported Leek", "Imported Leek Old", 
"Imported Nectarine", "Imported Peach", "Imported Pear", "Ismalilia Fass Mango", 
"Italian Basil Old", "Japanese Plum", "Kaka", "Kathaa", "kiwi", 
"Large Fruit Box", "Large Fruit Box Old", "Lebanese Apple", "Leek", 
"Local Apple", "Local Banana", "Local Celery ", "Local Cucumber", 
"Local Eggplant", "Local Hot Pepper", "Local Lemon", "Local Pear", 
"Maya Mango", "Medium Fruit Box", "Medium Fruit Box Old", "Melon", 
"Mexican Chili Pepper", "Mint", "Mint old", "Molokhia", "Momtaza Mango", 
"Momtaza Owais Mango", "Morket Tangerine", "Mushroom (200G)", 
"Mushroom (200G) old", "Naoumi Mango", "Navel Orange", "Nectarine Peach", 
"Nems Watermelon (KG)", "Okra", "Orange celery", "Orange For Juice", 
"Owais Mango", "Pack Of celery", "Parsle old", "Parsley", "Pineapple ( per KG)", 
"Polandian Apple", "Pomegranate", "Processing Peas ", "Pumpkin", 
"Raisin", "Red Cabbage", "Red Cabbage old", "Red Garlic", "Red Globe Grape", 
"Red Onion", "Red Radish", "Red Radish old", "Rosemary old", 
"Sadeeka Mango", "Santa Rosa Plum", "Saturn Nectarine", "Saturn Peach", 
"Sesame Dates", "Shalanteah Cantaloupe", "sobya", "Sobya", "Sokkary Mango", 
"Spanish Plum", "Spanish red plum", "Strawberry", "Sudanese Banana ", 
"Sugary Peach", "Superior Grape", "Sweet Apple", "Sweet Potato", 
"Syrian Green Apple", "Syrian plum", "Tamr 700G", "Tamr 700G Old", 
"Tamr hendi", "Taro", "Thyme Old", "Tomato", "Watermelon ( per KG)", 
"White Cabbage", "White Cabbage Old", "White Eggplant ", "White Prime Grape", 
"Yasmina Mango", "Zaghlol Dates", "Zebdaya Mango", "Zucchini"
), class = "factor"), col = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(" Fagr Mango", 
" Green Beans", "10075 - Bashmala", "Adalia Lemon", "African Crimson Grape", 
"African Pear", "Amar Eldain 400G", "Amar Eldain 400G Old", "American Plum", 
"Apricot", "Artichoke old", "Arugula", "Arugula old", "Arugula Rokla Old", 
"Autumn Royal Grape", "Avocado", "Baladi Cabbage", "Baladi Garlic", 
"Banati Grape", "Barbary Figs", "Barhi Dates", "Barshomi Figs", 
"Beet", "Black Eggplant", "Broccoli", "Cantaloupe", "Capsicum", 
"Carrot", "Cauliflower", "Chard", "Chard Old", "Cherry Tomatoes", 
"Chili Pepper", "Chinese Garlic", "Classic Eggplant", "coconut", 
"Cooking Potato", "Coriander", "Coriander old", "Crimson Grape", 
"Cucumber", "Deluxe Dried Dates", "Dessert Peach", "Dill", "Dill old", 
"Doum", "Dried Apricot", "Dried Dates", "Dried Figs 400G", "Dried Figs 400G Old", 
"Dried Plum", "Flame Grape", "Florida Peach", "Fons Mango", "Fruit Lovers", 
"Fruit Lovers Old", "frying Potato", "Gala Apple", "Ginger", 
"Ginger Old", "Golden Apple", "Golden Onion", "Golden Raisin", 
"Granny Apple", "Grape Leaves", "Greek Red Apple", "Greek sugar apple", 
"Green Latoga Lettuce  Old", "Green pepper", "Guava", "Hendi Mango", 
"Hibiscus", "Hollywood Plum", "Hot Pepper", "Iceberg Lettuce", 
"Iceberg Lettuce old", "Imported Apricot", "Imported Banana", 
"Imported Celery old", "Imported Cherry", "Imported Leek", "Imported Leek Old", 
"Imported Nectarine", "Imported Peach", "Imported Pear", "Ismalilia Fass Mango", 
"Italian Basil Old", "Japanese Plum", "Kaka", "Kathaa", "kiwi", 
"Large Fruit Box", "Large Fruit Box Old", "Lebanese Apple", "Leek", 
"Local Apple", "Local Banana", "Local Celery ", "Local Cucumber", 
"Local Eggplant", "Local Hot Pepper", "Local Lemon", "Local Pear", 
"Maya Mango", "Medium Fruit Box", "Medium Fruit Box Old", "Melon", 
"Mexican Chili Pepper", "Mint", "Mint old", "Molokhia", "Momtaza Mango", 
"Momtaza Owais Mango", "Morket Tangerine", "Mushroom (200G)", 
"Mushroom (200G) old", "Naoumi Mango", "Navel Orange", "Nectarine Peach", 
"Nems Watermelon (KG)", "Okra", "Orange celery", "Orange For Juice", 
"Owais Mango", "Pack Of celery", "Parsle old", "Parsley", "Pineapple ( per KG)", 
"Polandian Apple", "Pomegranate", "Processing Peas ", "Pumpkin", 
"Raisin", "Red Cabbage", "Red Cabbage old", "Red Garlic", "Red Globe Grape", 
"Red Onion", "Red Radish", "Red Radish old", "Rosemary old", 
"Sadeeka Mango", "Santa Rosa Plum", "Saturn Nectarine", "Saturn Peach", 
"Sesame Dates", "Shalanteah Cantaloupe", "sobya", "Sobya", "Sokkary Mango", 
"Spanish Plum", "Spanish red plum", "Strawberry", "Sudanese Banana ", 
"Sugary Peach", "Superior Grape", "Sweet Apple", "Sweet Potato", 
"Syrian Green Apple", "Syrian plum", "Tamr 700G", "Tamr 700G Old", 
"Tamr hendi", "Taro", "Thyme Old", "Tomato", "Watermelon ( per KG)", 
"White Cabbage", "White Cabbage Old", "White Eggplant ", "White Prime Grape", 
"Yasmina Mango", "Zaghlol Dates", "Zebdaya Mango", "Zucchini"
), class = "factor"), corr = c(100, 0, 0, 16.67, 0, 0, 0, 0, 
0, 0, 0, 33.33, 0, 0, 0, 0, 0, 16.67, 16.67, 16.67, 16.67, 33.33, 
0, 16.67, 0, 0, 50, 0, 0, 0, 0, 0, 16.67, 0, 33.33, 0, 0, 16.67, 
0, 0, 50, 0, 0, 16.67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 33.33, 
33.33, 0, 0, 16.67, 0, 0, 0, 16.67, 0, 0, 0, 33.33, 0, 33.33, 
0, 0, 16.67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33.33, 
0, 0, 0, 0, 0, 0, 0, 16.67, 0, 0)), .Names = c("row", "col", 
"corr"), row.names = c(NA, 100L), class = "data.frame")

我尝试这样做,但我没有得到结果。 这是我的ui.R代码

library(shiny)
fluidPage(
  titlePanel("Item Correlation"),
  sidebarPanel(
    selectInput("Item2","Select First Item",choices= DF$row)
  ),
  sidebarPanel(
    selectInput("Item","Select Second Item",choices= DF$col),

  mainPanel(
    tableOutput("Itemcorr")
  )
)
)

这是Server.R代码

library(shiny)
shinyServer(function(input,output){
  output$Itemcorr<- renderTable({
    ItemFilter<- subset(DF, DF$row ==input$item2)
  })
})

1 个答案:

答案 0 :(得分:2)

您的代码中存在一些问题

  • 输入ID Itemui.R
  • 中出现两次
  • 表格输出在Itemcorr中称为server.R,在DF$corr中称为ui.R
  • 我非常确定inputoutput ID不应包含$等特殊字符。
  • 您在input$item中使用server.R但未在item中的任何位置定义ui.R。您的意思是使用Item吗?
  • sidebarPanel
  • 中有两个ui.R
  • mainPanel包含在sidebarPanel
  • DF$corr中使用server.R对我没有意义。您的意思是使用DF$col吗?
  • renderTable中的表达式不会返回数据帧。

在发布有关SO的问题之前,请花更多时间阅读基本的闪亮文档。由于我已经看了一下,这里是你的应用程序的工作版本。 Hoepuffy它做你想要的。

library(shiny)
ui <- fluidPage(
  titlePanel("Item Correlation"),
  sidebarPanel(
    selectInput("Item2","Select First Item",choices= DF$row),
    selectInput("Item","Select Second Item",choices= DF$col)
  ),
  mainPanel(
    tableOutput("Itemcorr")
  )
)

server <- function(input,output){
  output$Itemcorr <- renderTable({
    subset(DF, DF$col == input$Item)
  })
}

shinyApp(ui, server)