小编Hen*_*ten的帖子

在 Shiny 中打印桑基图

我创建了一个像这样的桑基图:

#install.packages("networkD3")
library(networkD3)
nodes = data.frame("name" = 
                     c("Retour", # Node 0
                       "niet tevreden/ontevreden", # Node 1
                       "fout", # Node 2
                       "stuk",
                       "adres",
                       "verpakking",
                       "gebroken/glas"))# Node 3
links = as.data.frame(matrix(c(
  0, 1, 10, # Each row represents a link. The first number
  0, 2, 20, # represents the node being conntected from. 
  0, 3, 30,
  2, 4, 8,
  3, 5, 10,
  3, 6, 12# the second number represents the node connected to.
  ),# The third number is the value of the …
Run Code Online (Sandbox Code Playgroud)

r shiny sankey-diagram networkd3

7
推荐指数
1
解决办法
3215
查看次数

在闪亮的应用程序中包含自定义 CSS

我有以下闪亮的应用程序

ui.R

data("iris")
library(ggplot2)
library(dplyr)

ui <- fluidPage(theme = "mystyle.css",
  tabsetPanel(
    tabPanel("Tab 1", "Hello"),
    div(id = "box1", style="color:#0000FF", selectInput("boxplot1", "Choose a dataset:",
                choices = c(list("setosa", "versicolor", "virginica")))),
    div(id = "box2", selectInput("boxplot1", "Choose a dataset:",
                choices = c(list("setosa", "versicolor", "virginica"))))
  ),
  mainPanel(plotOutput("plot_boxplot"))
)
Run Code Online (Sandbox Code Playgroud)

服务器R

library(shiny)
library(datasets)

shinyServer(function(input, output) {

  filtered <- reactive({
    iris %>%
      filter(Sepal.Length >= 0)
  })

  output$plot_boxplot <- renderPlot({
    ggplot(filtered(), aes(x=Species, y=Sepal.Length)) + 
      geom_point(size = 4) + 
      geom_boxplot() +
      ylab("Sepal Length")  +
      stat_summary(fun.y=mean, geom="point", shape=5, size=4) 
  })


  # Generate …
Run Code Online (Sandbox Code Playgroud)

r shiny

5
推荐指数
1
解决办法
8942
查看次数

在ggplot2中添加一个簇的中心点

出于训练目的,我想创建一个 Shiny 应用程序,概述 KNN 算法中的步骤。我想要显示的第一步是两个集群的中心。

我使用 ggplot 首先显示 iris 数据集的 Sepal.Length 和 Sepal.Width。

library(ggplot2)

g <- ggplot(data=iris, aes(x=iris$Sepal.Length, y = iris$Sepal.Width))
g + geom_point()          
Run Code Online (Sandbox Code Playgroud)

然后我随机分配一个集群到集合中:

iris$Cluster <- 0
for(i in 1:nrow(iris)){
  randInt <- x1 <- round(runif(1, 0, 1),0)
  ifelse(randInt == 0,iris$Cluster[i] <- 1, iris$Cluster[i] <- 0)
}
iris$Cluster <- as.factor(iris$Cluster)                               
g <- ggplot(data=iris, aes(x=iris$Sepal.Length, y = iris$Sepal.Width, colour = Cluster))
g + geom_point()    
Run Code Online (Sandbox Code Playgroud)

现在我想采取的下一步是在我的图中显示一个点,它是集群 0 和集群 1 的中心。

关于如何在 ggplot2 中执行此操作的任何想法

r ggplot2

4
推荐指数
1
解决办法
1982
查看次数

使用操作按钮转到另一个选项卡

我有以下闪亮的应用程序:

ui <- fluidPage(
  tabsetPanel(
    tabPanel("Tab 1",
      actionButton("switch_tab", "Go to the second tab")
    ),
    tabPanel("Tab 2", "there!"),
    tabPanel("Tab 3", "there!"))

)

server <- function(input, output, session) {

  observeEvent(input$switch_tab, {
    updateTabsetPanel(session, "inTabset",
                      selected = "Tab 3")
  })

}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

当我单击“转到第二个选项卡”按钮时,它基本上应该切换选项卡。然而,它不起作用。

关于我可能忽略的任何反馈?

r shiny

4
推荐指数
1
解决办法
2393
查看次数

将文本标签添加到ggplot2镶嵌图中

使用以下数据:

Category <- c("Bankpass", "Bankpass", "Bankpass", "Moving", "Moving")
Subcategory <- c("Stolen", "Lost", "Login", "Address", "New contract")
Weight <- c(10,20,13,40,20)
Duration <- as.character(c(0.2,0.4,0.5,0.44,0.66))
Silence <- as.character(c(0.1,0.3,0.25,0.74,0.26))
df <- data.frame(Category, Subcategory, Weight, Duration, Silence)
Run Code Online (Sandbox Code Playgroud)

我用它来创建以下马赛克图:

library (ggplot2)
library (ggmosaic)

g <- ggplot(data = df) +
  geom_mosaic(aes(weight = Weight, x = product(Category), fill = Duration), 
              offset = 0, na.rm = TRUE) +  
  theme(axis.text.x = element_text(angle = -25, hjust = .1)) +
  theme(axis.title.x = element_blank()) +
  scale_fill_manual(values = c("#e8f5e9", "#c8e6c9", "#a5d6a7", "#81c784", "#66bb6a"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这是有效的,但我想在图表上的元素上包含文字标签("显示fe被盗,丢失"等) …

r ggplot2 ggmosaic

3
推荐指数
1
解决办法
1872
查看次数

从输入字段中删除标签

我有一个像这样的闪亮应用程序:

library(shiny)


UI <- fluidPage(
  numericInput("obs", "Observations:", 10, min = 1, max = 100),
  numericInput("obs", "Observations:", 10, min = 1, max = 100)
)
Server <- function(input, output) {}

shinyApp(ui = UI, server = Server)
Run Code Online (Sandbox Code Playgroud)

如果我删除这样的标题:

UI <- fluidPage(
  numericInput("obs", "", 10, min = 1, max = 100),
  numericInput("obs", "", 10, min = 1, max = 100)
)
Server <- function(input, output) {}

shinyApp(ui = UI, server = Server)
Run Code Online (Sandbox Code Playgroud)

我仍然有空白漂浮在输入字段上方。关于我如何摆脱这个的任何想法?

r shiny

3
推荐指数
1
解决办法
713
查看次数

将地图上的状态转换为Shiny中的可点击对象

我有以下闪亮的应用程序:

library(shiny)
library(rhandsontable)
library(shinydashboard)
library(ggplot2)
library(dplyr)



shinyApp(
  ui = dashboardPage(
    dashboardHeader(
      title = "Tweetminer",
      titleWidth = 350
    ),
    dashboardSidebar(
      width = 350,
      sidebarMenu(
        menuItem("Menu Item")
      )
    ),
    dashboardBody(
      fluidRow(
        tabBox(
          tabPanel("Set tweets2", 
                   plotOutput('plot',
                              brush = brushOpts(
                                id = "plot1_brush"
                              )),
                   h4("Selected States"),
                   verbatimTextOutput("select_states"),
                   h4("Selected States' Tweets"),
                   verbatimTextOutput("tweets"),
                   h4("Selected States' Amount"),
                   textOutput("test1")#,
                   #actionButton("button", textOutput("test1"))
          )
        )
      )
    )
  ),
  server = function(input, output) { 

    output$plot <- renderPlot({

      all_states <- map_data("state") 
      states_positive <- c("louisiana", "alaska", "new york")

      # Plot results
      ggplot(all_states, aes(x=long, …
Run Code Online (Sandbox Code Playgroud)

r shiny shinydashboard

3
推荐指数
1
解决办法
1584
查看次数

在Shiny应用程序中仅选择地图中的一个状态

我有以下数据集:

library(rgdal)
library(leaflet)

tmp <- tempdir()
url <- "http://personal.tcu.edu/kylewalker/data/mexico.zip"
file <- basename(url)
download.file(url, file)
unzip(file, exdir = tmp)
mexico <- readOGR(dsn = tmp, layer = "mexico", encoding = "UTF-8")

pal <- colorQuantile("YlGn", NULL, n = 5)
state_popup <- paste0("<strong>Estado: </strong>", 
                  mexico$name, 
                  "<br><strong>PIB per c?pita, miles de pesos, 2008: </strong>", 
                  mexico$gdp08)
Run Code Online (Sandbox Code Playgroud)

除了这些数据之外,我还构建了以下Shiny应用程序:

# load necessary packages
library(leaflet)    
library(shiny)
library(shinydashboard)


ui <- fluidPage(
  # place the contents inside a box
  shinydashboard::box(
    width = 12
    , title = "Click on the map!"
    # …
Run Code Online (Sandbox Code Playgroud)

r rgdal leaflet shiny r-leaflet

3
推荐指数
1
解决办法
1256
查看次数

如何为项目符号图表添加自定义图例

我有以下数据集:

incidents.pct <- data.frame(
  measure=c("Total Events (%)", "Security Events (%)", "Filtered (%)", "Tickets (%)"),
  high=c(100,100,100,100),
  mean=c(45,40,50,30),
  low=c(25,20,10,5), 
  target=c(55,40,45,35),
  value=c(50,45,60,25))
Run Code Online (Sandbox Code Playgroud)

我用它来创建以下"子弹般的"图形.

g <- ggplot(incidents.pct) +
  geom_bar(aes(measure, high),  fill="goldenrod2", stat="identity", width=0.5, alpha=0.2) +
  geom_bar(aes(measure, mean),  fill="goldenrod3", stat="identity", width=0.5, alpha=0.2) +
  geom_bar(aes(measure, low),   fill="goldenrod4", stat="identity", width=0.5, alpha=0.2) +        
  geom_point(aes(measure, target), colour="red", size=2.5) 
Run Code Online (Sandbox Code Playgroud)

这有效,但我希望包含一个解释颜色的自定义图例.所以只是一个带有"低","中等","价值"等的颜色标志......

有关如何包含此内容的任何建议吗?

r ggplot2

2
推荐指数
1
解决办法
351
查看次数

在Shiny Application中过滤数据时,除第一个元素外,长度为1的所有字符向量都会被忽略错误

我有以下闪亮的应用程序:

library(shiny)
library(rhandsontable)
library(shinydashboard)
library(ggplot2)
library(dplyr)

setwd("C:/Users/Marc/Dropbox/PROJECTEN/Lopend/shiny_interactive_graph")

tweets <- data.frame(
  city = c("new york", "texas", "texas"),
  tweet = c("Test1", "Test", "tst")
)


shinyApp(
  ui = dashboardPage(
    dashboardHeader(
      title = "Tweetminer",
      titleWidth = 350
    ),
    dashboardSidebar(
      width = 350,
      sidebarMenu(
        menuItem("Menu Item")
      )
    ),
    dashboardBody(
      fluidRow(
        tabBox(
          tabPanel("Set tweets2", 
                   plotOutput('plot',
                              brush = brushOpts(
                                id = "plot1_brush"
                              )),
                   h4("Selected States"),
                   verbatimTextOutput("select_states"),
                   h4("Selected States' Tweets"),
                   verbatimTextOutput("tweets")
          )
        )
      )
    )
  ),
  server = function(input, output) { 

    output$plot <- renderPlot({

      all_states <- map_data("state") 
      # …
Run Code Online (Sandbox Code Playgroud)

r modal-dialog dataframe shiny

2
推荐指数
1
解决办法
1434
查看次数

在 Shiny 应用程序中存储 RHandsontable 的编辑

我有一个 Shiny 应用程序,它可以读取 .csv 文件并生成一个可编辑的表格。

library(dplyr)
library(rhandsontable)
options(shiny.maxRequestSize = 9*1024^2)

function(input, output) {

  values <- reactiveValues()

  Post <- c("Bank", "Bank")
  list2 <- c(12,13)
  df <- data.frame(Post, list2)

  Post <- c("Ba", "Ba")
  list2 <- c(12,13)
  df2 <- data.frame(Post, list2)

  performTextMining <- reactive({
    df$Post <- as.character(df$Post)
    df <- df %>% filter(Post == "Bank")   
    return(df)
  })

  output$contents <- renderRHandsontable({

    items <- c("Boodschappen", "Noodzakelijk")
    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    df <- read.csv(inFile$datapath, header = input$header,
             sep = input$sep, quote = input$quote)
    #performTextMining()
    rhandsontable(df, …
Run Code Online (Sandbox Code Playgroud)

r shiny rhandsontable

1
推荐指数
1
解决办法
1010
查看次数

在 Shiny 中使用模态对话框创建多个按钮

我有以下闪亮的应用程序:

library(shiny)
library(shinyBS)

UI <- shinyUI(fluidPage(

  fluidRow(
    column(10,
           plotOutput("line_graph")),
    #Pop up windows, for three buttons on the left side
    bsModal("modalExample1", "Your plot", "a_plot", size = "large",
            plotOutput("plot1"), downloadButton('downloadPlot', 'Download')),
    #bsModal("modalExample2", "Your plot", "b_plot", size = "large",
    #        plotOutput("plot2"), downloadButton('downloadPlot', 'Download')),



    column(2,
           actionButton("a_plot","Bubble chart"),
           actionButton("b_plot","Graph view"))
  )
))

Server <- function(input, output) {

  output$line_graph <- renderPlot({hist(10)})
  output$plot1 <- renderPlot({hist(20)})
  output$plot2 <- renderPlot({hist(30)})



}
shinyApp(ui = UI, server = Server)
Run Code Online (Sandbox Code Playgroud)

当我按下按钮“a_plot”时,您会看到一个带有图形的弹出窗口。这有效。但是,我还想实现当我按下“b_plot”时会弹出另一个图形。

但是,当我取消注释此代码时:

这是行不通的。关于我如何让这个工作的任何反馈?

#bsModal("modalExample2", "Your plot", "b_plot", size = "large",
#        plotOutput("plot2"), …
Run Code Online (Sandbox Code Playgroud)

r shiny

1
推荐指数
1
解决办法
896
查看次数

摆脱句子中的输入空格

我有一个看起来像这样的字符串:

<type 'str'>
Hi George,

Thanks for sending me your report.

Ill take a look at it and get back to you tomorrow.
Run Code Online (Sandbox Code Playgroud)

我想要做的是将其转换为一个字符串,如下所示:

Hi George, Thanks for sending me your report. Ill take a look at it and get back to you tomorrow.
Run Code Online (Sandbox Code Playgroud)

怎么想我怎么做?

python

0
推荐指数
1
解决办法
96
查看次数