我怎样才能阅读闪亮的xls? R-工作室
How can I read a xls in shiny? R-Studio
我正在使用 shiny,因为我想做一个仪表板,但是当我做一个绘图时出现了一些错误。我想从我自己电脑上的文件中读取数据库。
我不要这个https://jamesmccammon.com/2014/12/29/shiny-web-app/
#ui
library(shinydashboard)
sidebar <- dashboardSidebar(
hr(),
sidebarMenu(id="tabs",
menuItem("a", tabName="a", icon=icon("pagelines"), selected=TRUE),
menuItem("b", icon=icon("chart-bar"),
menuItem("c", tabName = "c", icon=icon("chart-bar")),
menuItem("d", tabName = "d", icon = icon("chart-bar")),
menuItem("e", tabName = "e", icon=icon("mortar-board")),
menuItem("f", tabName = "f", icon = icon("question"))
),width = 285
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "a",
withMathJax(),
includeMarkdown("principal.Rmd")
),
tabItem(tabName = b",
dateRangeInput('b_fecha',
label = 'Por favor seleccionar fecha:',
start = Sys.Date() - 2, end = Sys.Date() + 2, format = "mm yyyy", startview = 'year', language = 'es'
),
column(width = 8,
box( width = NULL, plotOutput(outputId = "b_iden_grap"), collapsible = TRUE,
title = "Plot", status = "primary", solidHeader = TRUE)
)
)
))
dashboardPage(
dashboardHeader(title = "title", titleWidth=285),
sidebar,
body
)
# server
library(shinydashboard)
library(shiny)
library(readxl)
library(zoo)
shinyServer(function(input, output) {
df1.1.1=data.frame(read_excel("C:/Users/.../Base.xlsx", sheet = "1.1.1"))
df1.1.1$mes.y.año = as.yearmon(as.Date(df1.1.1$mes.y.año, origin="1899-12-30"))
output$admision_iden_grap <- renderPlot({
plot(df1.1.1$mes.y.año, (1-(df1.1.1$errores/df1.1.1$egresos))*100, ylim= c(0,100), type ="h")
})
})```
shiny::runApp('C:/.../...') Loading required package: shiny
Listening on http://###.#.#.#:####
Attaching package: ‘shinydashboard’
The following object is masked from ‘package:graphics’:
box
Warning in checkEncoding(file) :
The input file C:...\Prueba/server.R does not seem to be encoded in UTF8 Warning in readLines(file, warn = FALSE) :
invalid input found on input connection 'C:.../server.R' Error in parse(file, keep.source = FALSE, srcfile = src, encoding = enc) :
C:.../server.R:11:0: unexpected end of input
9: df1.1.1=data.frame(read_excel("C:/Users/.../Base.xlsx", sheet = "1.1.1"))
10: df1.1.1$mes.y.a
^ Warning: Error in sourceUTF8: Error sourcing C:...\AppData\Local\Temp\RtmpwbMkRB\file42c486c4a65
[No stack trace available] Error in sourceUTF8(serverR, envir = new.env(parent = globalenv())) : Error sourcing
C:...\AppData\Local\Temp\RtmpwbMkRB\file42c486c4a65
问题是由于 ñ
这样的特殊字符引起的。
正如您在警告消息中所见:
The input file C:...\Prueba/server.R does not seem to be encoded in
UTF8
因此请以 UTF8 编码保存您的文件。要在 RStudio 中执行此操作,请执行 File -> Save with encoding
(如果仍然不起作用,请删除特殊字符)。
我正在使用 shiny,因为我想做一个仪表板,但是当我做一个绘图时出现了一些错误。我想从我自己电脑上的文件中读取数据库。
我不要这个https://jamesmccammon.com/2014/12/29/shiny-web-app/
#ui
library(shinydashboard)
sidebar <- dashboardSidebar(
hr(),
sidebarMenu(id="tabs",
menuItem("a", tabName="a", icon=icon("pagelines"), selected=TRUE),
menuItem("b", icon=icon("chart-bar"),
menuItem("c", tabName = "c", icon=icon("chart-bar")),
menuItem("d", tabName = "d", icon = icon("chart-bar")),
menuItem("e", tabName = "e", icon=icon("mortar-board")),
menuItem("f", tabName = "f", icon = icon("question"))
),width = 285
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "a",
withMathJax(),
includeMarkdown("principal.Rmd")
),
tabItem(tabName = b",
dateRangeInput('b_fecha',
label = 'Por favor seleccionar fecha:',
start = Sys.Date() - 2, end = Sys.Date() + 2, format = "mm yyyy", startview = 'year', language = 'es'
),
column(width = 8,
box( width = NULL, plotOutput(outputId = "b_iden_grap"), collapsible = TRUE,
title = "Plot", status = "primary", solidHeader = TRUE)
)
)
))
dashboardPage(
dashboardHeader(title = "title", titleWidth=285),
sidebar,
body
)
# server
library(shinydashboard)
library(shiny)
library(readxl)
library(zoo)
shinyServer(function(input, output) {
df1.1.1=data.frame(read_excel("C:/Users/.../Base.xlsx", sheet = "1.1.1"))
df1.1.1$mes.y.año = as.yearmon(as.Date(df1.1.1$mes.y.año, origin="1899-12-30"))
output$admision_iden_grap <- renderPlot({
plot(df1.1.1$mes.y.año, (1-(df1.1.1$errores/df1.1.1$egresos))*100, ylim= c(0,100), type ="h")
})
})```
shiny::runApp('C:/.../...') Loading required package: shiny Listening on http://###.#.#.#:#### Attaching package: ‘shinydashboard’ The following object is masked from ‘package:graphics’: box Warning in checkEncoding(file) : The input file C:...\Prueba/server.R does not seem to be encoded in UTF8 Warning in readLines(file, warn = FALSE) : invalid input found on input connection 'C:.../server.R' Error in parse(file, keep.source = FALSE, srcfile = src, encoding = enc) : C:.../server.R:11:0: unexpected end of input 9: df1.1.1=data.frame(read_excel("C:/Users/.../Base.xlsx", sheet = "1.1.1")) 10: df1.1.1$mes.y.a ^ Warning: Error in sourceUTF8: Error sourcing C:...\AppData\Local\Temp\RtmpwbMkRB\file42c486c4a65 [No stack trace available] Error in sourceUTF8(serverR, envir = new.env(parent = globalenv())) : Error sourcing C:...\AppData\Local\Temp\RtmpwbMkRB\file42c486c4a65
问题是由于 ñ
这样的特殊字符引起的。
正如您在警告消息中所见:
The input file C:...\Prueba/server.R does not seem to be encoded in UTF8
因此请以 UTF8 编码保存您的文件。要在 RStudio 中执行此操作,请执行 File -> Save with encoding
(如果仍然不起作用,请删除特殊字符)。